CET
CET

Reputation: 312

Make Strongly Typed List Public?

If I have a SubPage within the frame content of my MainPage with the following code

List<Lookup> Lookups = new List<Lookup>

How do I make it public so I can access Lookups from MainPage.xaml.cs?

Upvotes: 1

Views: 42

Answers (2)

Muhammad Touseef
Muhammad Touseef

Reputation: 4465

use static to keep it just once instance for that page and use public to access is outside the SubPage class.

public static List<Lookup> Lookups = new List<Lookup>

Now when you want to use it within any other class even in MainPage you can just use it with the name of the subpage class like following.

SubPage.Lookups.Add()...

Please note that you dont need to create a new instance of subpage ( new SubPage() ) to use the lookups object because it is static.

Upvotes: 1

Neil
Neil

Reputation: 11889

I might be missing something, but have you tried putting public at the start of the line?

public List<Lookup> Lookups = new List<Lookup>();

Although it would be better as a property

private List<Lookup> _lookups = new List<Lookup>();
public IEnumerable<Lookup> Lookups => _lookups;

Upvotes: 2

Related Questions