This is a follow up question from another post but that post was answered. I have a for loop that I want to add three items to a generic class and I’m not sure how to do that. How do I add those items?
private static void TestResults()
{
List<Record> Records = new List<Record>();
for (int i = 0; i < ProxyList.Count; i++)
{
string[] split = List[i].Split('|');
// This is what i dont know how to do
// split[0] = Name, split[1] = SomeValue and split[3] = OrderNr
}
}
class Records
{
public static string Name { get; set; }
public static int SomeValue { get; set; }
public static int OrderNr { get; set; }
}
Well for one thing, your properties must not be static. You want different data for each instance, right? So they need to be instance properties. Personally I’d also make the type immutable, but that’s another matter:
As of C# 3 / .NET 3.5, a more idiomatic approach would be to use LINQ:
… on the other hand, that’s relatively advanced if you’re really just starting to learn the language.
To be honest, Stack Overflow is better for asking specific questions than structured learning – I suggest you get hold of a good book, such as C# 4 in a Nutshell.