सबसे पहले, खाली स्ट्रिंग वाली सूची को तत्वों के रूप में सेट करें।
List<string> myList = new List<string>() {
" ",
" ",
" "
}; आइए अब अनुक्रमणिका का उपयोग करके एक खाली तत्व को हटा दें।
myList.RemoveAt(0);
उदाहरण
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main() {
List<string> myList = new List<string>() {
" ",
" ",
" "
};
Console.Write("Initial list with empty strings...\n");
foreach (string list in myList) {
Console.WriteLine(list);
}
Console.Write("Removing an empty element from the list...\n");
myList.RemoveAt(0);
foreach (string list in myList) {
Console.WriteLine(list);
}
Console.WriteLine("Empty List after deleting an empty element is shown above...");
}
} आउटपुट
Initial list with empty strings... Removing an empty element from the list... Empty List after deleting an empty element is shown above...