1

in c#, let's suppose that i have a class like as follows..

public class anItem
    {
        public string name { get; set; }
        public string surname { get; set; }
    }

and i use a generic list with that object, like.

List<anItem> listof = new List<anItem>();
listof.Add(new anItem { name = "name 1", surname = "surname 1" });
listof.Add(new anItem { name = "name 2", surname = "surname 2" });
listof.Add(new anItem { name = "name 3", surname = "surname 3" });
listof.Add(new anItem { name = "name 4", surname = "surname 4" });

is it possible take all surname 's from listof generic list to a string array ?

string[] takenSurnames = // take just surnames from listof

yes i can get that with foreach or for loops. but i wonder if there's any lambda expression or something like that shorter ?

Thanks in advance..

1 Answer 1

4
listof.Select(c => c.surename).ToArray();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.