Reputation: 3
Hello. I am using xamaring forms to create an app and I am having problems obtaining a certain value from an object.
Essentially I would like to take Address1 from the object e.SelectedItem and place it into a string called address. I plan to do this to all the variables in the object, so address, city, country, postal code, etc...
From here I will use these strings to form a url link that will take the user to their native map application with the address inputed into the url.
Note: The line of text I have var item = e.SelectedItem;
was added for testing purposes.
Below I have some code:
async void AddressItemSelected(object sender, SelectedItemChangedEventArgs e)
{
if (e.SelectedItem != null)
{
var item = e.SelectedItem;
}
}
In summary: I would like to take the variables stored in an object and place them into their own string element.
Thank you!
Upvotes: 0
Views: 75
Reputation: 499
my suggestion would be cast your item NOT as "var", cast it as your exact class type.
Class item = (Class)e.selectedItem
Upvotes: 0
Reputation: 89127
you need to cast
the object to the correct type first
var item = (MyClass)e.SelectedItem;
var addr1 = item.Address1
Upvotes: 3