Answer the question
In order to leave comments, you need to log in
Populate list instance dynamically?
Hi there is a code that has a List where it should be filled example with data new Employee(0, 200)
using System;
using System.Collections.Generic;
public class Employee
{
public int place;
public int score;
public Employee(int place, int score)
{
this.place = place;
this.score = score;
}
public override string ToString() {
return "" + place + "";
}
}
public class Example
{
public static void Main()
{
Employee first = new Employee(0, 200);
//тут заполняем лист
List<List<object>> list = new List<List<object>>();
list.Add(new List<object>{});
list[0].Add(new Employee(0, 200));
// сюда его передаем
List<Employee> employees = new List<Employee>(){ list };
employees.Sort(delegate(Employee x, Employee y) {
return x.score.CompareTo(y.score);
});
employees.Reverse();
Console.WriteLine(String.Join(Environment.NewLine, employees));
}
}
Answer the question
In order to leave comments, you need to log in
well, it’s not a beautiful code at all, but if you really really need it, then write it like this:
var employeeList = objListList[0].Select(x=>x as Employee).ToList();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question