Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hello Friends,

I have 3 List. I want to add that 3 List into 1 list.
Can i do this?

My Code is as below.

C#
List<SMS> _sms = new List<SMS>();
List<Contacts> _contacts = new List<Contacts>();
List<PinCode> _pinCode = new List<PinCode>();


i want to add this 3 list into

C#
List<PhysicalResult> _PhysicalResult = new List<PhysicalResult>();


I tried

C#
_PhysicalResult.AddRange(_contacts);


But its not working.
Can you please help me?

Thanks,
Viprat
Posted

1 solution

Hi,

Ofcourse that will not work as you are passing typed value in list.

Instead use below code,
C#
List<dynamic> _PhysicalResult = new List<dynamic>();
_PhysicalResult.AddRange(_contacts);

Above code will work if you are using Framework 4.0.

If you want it in older version then you can use List<object> instead List<dynamic>

Thanks
 
Share this answer
 
v2
Comments
AmitGajjar 19-Sep-12 3:40am    
Please see my updated answer.
AmitGajjar 19-Sep-12 3:46am    
Any reason for negative vote ?

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