Click here to Skip to main content
15,877,857 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello!

I have this lambda expression

.Select(res => new {res.YEAR, res.Week, res.Number});

How can i combine res.YEAR, res.Week into one string in a lambda expression?

I also want to do a substring on the Year, is this possible?

Thanks!
Posted

1 solution

Hi!

Yes, that is all possible. Using an anonymous class as in your example:
C#
.Select(res => new
            {
                Combination = res.Week + res.Year,
                Substring = res.Year.Substring(0, 2)
            });


Or if you want a simple list of strings:

C#
.Select(res => res.Year.Substring(0, 2))

or
C#
.Select(res => res.Week + ", " + res.Year)
 
Share this answer
 
Comments
CrafterIt 26-May-11 6:08am    
Thanks for the reply :)
parmar_punit 26-May-11 6:40am    
good answer, my 5
Kim Togo 26-May-11 7:54am    
Good answer, my 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900