Reputation: 4516
I have a small question, I'm sure it was answered but I just not sure what to look for.
I have the following code:
hotel = MatchHotelFromList(lst, hotel);
Where my method:
private Hotel MatchHotelFromList(List<Hotel> lst, Hotel hotel)
{
// do some stuff --> find a specific hotel in list, using 'hotel'
// returns a specific hotel object.
}
I want to do the same but use the method without sending 'hotel' :
hotel = MatchHotelFromList(lst);
Can I use the values from 'hotel' in the method? (like this.HotelName?)
Upvotes: 0
Views: 35
Reputation: 3182
now you can use the method without sending 'hotel' object
private Hotel MatchHotelFromList(List<Hotel> lst)
{
// do some stuff --> find a specific hotel in list, using 'hotel'
// returns a specific hotel object.
}
no you can't access hotel object data or property using above methord else
if you don't want to pass as parameter then declare a field of hotel object now you can get access to hotel object
Private Hotel hotel;
private Hotel MatchHotelFromList(List<Hotel> lst)
{
// do some stuff --> find a specific hotel in list, using 'hotel'
// returns a specific hotel object.
}
Upvotes: 0
Reputation: 203817
No, there is no way for the method to access the value of the variable that its result is being assigned to.
Given that there are all sorts of things that can be done with the result of the method besides assigning it to a variable, this shouldn't come as much of a shock.
What if the result of the method is ignored? What if it's passed as a parameter to another method? What if it's being assigned to a set-only property? What if it's being assigned to an uninitialized variable? I could go on, but I hope you get the idea.
Upvotes: 1