How to clear ienumerable object

I have on IEnumerable
I have one button to load the list and one button to delete the list
the question is how can I delete clear the content of the list?

private static IEnumerable<string> wordlist { get; set; }

for loading

 public void setWordlist(string filePath)
        {
            wordlist = File.ReadLines(filePath);
        }

how can I clear the list?

Just set wordlist to a new empty array or list. The garbage collector will delete the old one if it’s not referenced anymore.

wordlist = Array.Empty<string>();

or

wordlist = new List<string>();
1 Like

When I click the delete button I called this function

public void clearWoldlist()
        {
            wordlist = new List<string>();
        }

but the thing is I show a notification on desktop when I click on the delete button. It shows notification even if the file is not loaded yet
here is the code

 helper.clearWoldlist();
            Growl.WarningGlobal($"{fileName} deleted successfully!");
            btnLoadCombo.Content = "Load Combo";
            btnDeleteCombo.Foreground = new SolidColorBrush(Colors.White);
            badgeDeleteCombo.Background = new SolidColorBrush(Colors.White);
            badgeDeleteCombo.Foreground = new SolidColorBrush(Colors.White);
            btnDeleteCombo.BorderBrush = new SolidColorBrush(Colors.White);

I know code is behaving right as I didn’t warp it in if else my question is how can I wrap the code the it only shows the notification when there exist a content in wordlist like the list is already been loaded

if (wordlist.Count() > 0)
{
  helper.clearWoldlist();
  // blah blah
}

come on man these are the basics ^^

1 Like

Thanks and sorry, but I’m still learning :laughing: