How to remove the last value from a list in C#

1 Answer

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

class Program
{
    static void Main() {
        List<string> list = new List<string>() { "c#", "c", "java", "python", "php" };

        if (list.Count > 0) {
            list.RemoveAt(list.Count - 1);
        }

        Console.WriteLine(string.Join(" ", list));
    }
}



/*
run:

c# c java python

*/

 



answered Aug 7, 2023 by avibootz

Related questions

1 answer 100 views
1 answer 185 views
1 answer 113 views
1 answer 264 views
1 answer 105 views
...