2
Answers

I need some help to understand lambad expresion

Photo of Catalin Radu

Catalin Radu

7y
618
1
I know this might sound very stupid but can someone explain to me why the following code do not work? and maybe some tutorial for dummie on lambad:
  1. int test = 1;  
  2.         int testLambadIndex = rooms.FindIndex (r => (Room.LastCreatedRoomAt)r.lastCreatedRoomAt = (Room.LastCreatedRoomAt)test);  
i try to use this enum from Room class 
  1. public enum LastCreatedRoomAt{North = 1,South,West,East,None};  
rooms is a list of type Room.
 

Answers (2)

1
Photo of Dharmraj Thakur
254 7.7k 719.6k 7y
What is the reason behind type casting in your expression. I you want to find index of specific record then you can do simply like this...
  1. List<Room> rooms = new List<Room>();  
  2. int test = 1;  
  3. int testLambadIndex = rooms.FindIndex(r => r.ID == test); 
 
1
Photo of Catalin Radu
NA 30 3.2k 7y
Btw, i have the next error:
Assets/_Scripts/RoomGenerator.cs(37,47): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer