I am learning user controls in C# so basically I have a class called Books. In this class I have a static method public static string[] GetBooks(), this method returns the booknames.
public static string[] GetBooks()
{
return myBookList.ToArray();
}
Now I have a UserControl where I placed a DataGrid, and I want to be able to do something like dataGrid.DataSource = Books.GetBooks();.
The problem is that the intellisense is not getting the .GetBooks() and I think it is because it is static and I want to keep it static. How can I do this and also, where would the best place to make this call? I assume in the behing code file of ascx right?
Why? Does it make sense for this method to be static, i.e., would it be reasonable to assume that all instances of
Bookswould share the same underlying Book data? If not then it shouldn’t be static.If it should be static then you need to reference it like so (as opposed to using an instance reference)
I assume you have something like this right now: