How to remove element from a List in C#

1 Answer

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

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> list = new List<int>();

            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            list.Add(5);

            try
            {
               list.Remove(2);

               foreach (int n in list)
                    Console.WriteLine(n);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}


/*
run:
    
1
3
4
5
  
*/

 



answered Feb 10, 2017 by avibootz
edited Feb 10, 2017 by avibootz

Related questions

1 answer 141 views
1 answer 187 views
1 answer 142 views
1 answer 68 views
3 answers 240 views
1 answer 143 views
1 answer 175 views
...