[Mono-list] Simple List problem which is causing me a right royal issue!

Paul Johnson paul at all-the-johnsons.co.uk
Sun Apr 1 21:58:15 UTC 2012


This is probably something seriously simple to solve, but my brain is
telling me otherwise.

My code is as follows

using System;
using System.Collections.Generic;

namespace ListProblems
    internal class Program
        public class vars
            public string foo;
            public string bar;
            public int a;
            public bool b;
            public char c;
            public double d;

        private static void Main(string[] args)
            var c = new List<vars>();
            c[0].foo = "hello"; // dies - index out of bounds
            Console.WriteLine("c[0] = {0}", c[0].foo);

Problem is really straight forward. How do I add something directly
into c? c.Add() is not going to work as c is a List of class vars.

Any help would be appreciated here.



More information about the Mono-list mailing list