I am trying to make a list of objects in C#. The list of object i have to pass to a method which extracts the object name, object properties and values for each object from list. following are the code.
//Class B
public class ClassB
{
public string Prop1 { get; set; }
public string Prop2 { get; set; }
public int Prop3 { get; set; }
public int Prop4 { get; set; }
}
// Class C
public class ClassC
{
public string ClassCProp1 { get; set; }
public string ClassCProp2 { get; set; }
public int ClassCProp3 { get; set; }
public int ClassCProp4 { get; set; }
}
List
List inputToCsv = new List();
for (int i = 0; i < 5; i++)
{
ClassB CB = new ClassB();
CB.Prop1 = i.ToString();
CB.Prop2 = i.ToString() + ") ClassB _ RDS";
CB.Prop3 = 100000 + i;
CB.Prop4 = 199999 + i;
inputToCsv.Add(CB);
}
objList.Add(inputToCsv);
List inputToClassC = new List();
for (int i = 0; i < 5; i++)
{
ClassC CB = new ClassC();
CB.ClassCProp1 = i.ToString();
CB.ClassCProp2 = i.ToString() + ")ClassC _ RDS";
CB.ClassCProp3 = 100000 + i;
CB.ClassCProp4 = 199999 + i;
inputToClassC.Add(CB);
}
objList.Add(inputToClassC);
now i have to pass this "objList" object to next method. and catch the object name from list. Here I am able to get the name using "Type objtype = new objList..GetType()". But i m getting List1 as name. I want ClassB / ClassC as name of object can u plz suggest something using generic solution for this.
VulpesPosted Jan 13, 2014, 9:16 AM
Sagar PardeshiPosted Jan 13, 2014, 2:07 AM
http://social.msdn.microsoft.com/Forums/en-US/f6a9b944-1b0d-4fa0-a0dd-e40d11af3454/linq-c-how-to-get-object-from-list-based-on-object-variables?forum=linqprojectgeneral
http://msdn.microsoft.com/en-us/library/bb397900.aspx