I want a method to return a list which contains two more list which are having two different data types, like :
List<List<object>> parentList = new List<List<object>>();
List<string> childList1 = new List<string>();
List<DataRow> childList2 = new List<DataRow>();
parentList.Add(childList1);
parentList.Add(childList2);
return parentList;
As per above code I am getting an error
The best overloaded method match for 'System.Collections.Generic.List>.Add(System.Collections.Generic.List)' has some invalid arguments
Please can anyone suggest me the best approach to handle this.
Thanks
Lists are the most versatile of Python's compound data types. A list contains items separated by commas and enclosed within square brackets ([]). To some extent, lists are similar to arrays in C. One difference between them is that all the items belonging to a list can be of different data type.
A nested list is a list of lists, or any list that has another list as an element (a sublist). They can be helpful if you want to create a matrix or need to store a sublist along with other data types.
What about creating an object of your class as like this?
public class myParent
{
public List<string> childList1 = new List<string>();
public List<DataRow> childList2 = new List<DataRow>();
}
public void someFun()
{
List<myParent> parentList = new List<myParent>();
myParent myParentObject = new myParent();
myParentObject.childList1 = new List<string>() { "sample" };
myParentObject.childList2 = new List<DataRow>() { };
parentList.Add(myParentObject);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With