Sunday, February 23, 2014

CSharp C# List item dynamically edited

CSharp C# List item dynamically edited

The following is an example of editing an item in a list dynamically





using System;
using System.Collections.Generic;
using System.Management.Instrumentation;
using System.Text;
using System.Runtime.InteropServices;

namespace ConsoleStuff
{
    class Program
    {
        private static List<myclass> mc;
        static void Main(string[] args)
        {
            //------------------------------------------------------
            mc = new List<myclass>();
            mc.Add(new myclass{sString="fun n games"});
            Console.WriteLine("mc[0].sString={0}", mc[0].sString);
            mc[0].sString = "no longer fun n games now";
            Console.WriteLine("mc[0].sString={0}", mc[0].sString);
            //------------------------------------------------------
            Console.WriteLine("press enter to finish");
            Console.ReadLine();
        }
    }

    public class myclass
    {
        public string sString { get; set; }
    }
}



No comments:

Post a Comment