Welcome to collectivesolver - Programming & Software Q&A with Examples. A website you can trust. All programs tested and work.

Contact: aviboots(AT)netvision.net.il


Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Dental Dog Chews
FRESH BREATHIES

GlucoTrust is a brand new, science-backed supplement that supports healthy blood sugar levels AND weight loss for men and women

Everything you need to sell anywhere

Managed VPS Hosting
Affordable. Secure. Your Own Virtual Private Hosting. Faster than AWS and Rackspace

Bonsai Boy of New York Bonsai Trees and Accessories
100%

Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

24,887 questions

32,502 answers

573 users

How to create a list of objects in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;

public class program
{
    private string name;
    private int age;
    private string programming;

    public program(string name, int age, string programming) {
        this.name = name;
        this.age = age;
        this.programming = programming;
    }
    public string Name {
        get{return name;}
    }
    public int Age {
        get{return age;}
    }
    public string Programming {
        get{return programming;}
    }
}

public class main 
{
    public static void Main()
    {

        List<program> list = new List<program>();
        
        list.Add(new program("Liam", 45, "c#"));
        list.Add(new program("Noah", 39, "java"));
        list.Add(new program("Emma", 51, "python"));


		foreach(var item in list)
			Console.WriteLine("{0} - {1} - {2}", item.Name, item.Age, item.Programming);
    }
}




/*
run:

Liam - 45 - c#
Noah - 39 - java
Emma - 51 - python

*/

 




answered 2 days ago by avibootz
...