© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•16mo ago•
22 replies
tommy

✅ Difference between `string[]` and `IEnumerable<string>`

in the following the code, the output seems to be the same:
using System;
using System.IO;

class Program
{
  public static void Main()
  {
    foreach (string dir in Directory.GetDirectories("Settings"))
      Console.WriteLine(dir);
    
    foreach (string dir in Directory.EnumerateDirectories("Settings"))
      Console.WriteLine(dir);
  }
}
using System;
using System.IO;

class Program
{
  public static void Main()
  {
    foreach (string dir in Directory.GetDirectories("Settings"))
      Console.WriteLine(dir);
    
    foreach (string dir in Directory.EnumerateDirectories("Settings"))
      Console.WriteLine(dir);
  }
}


i know that
enum
enum
s are used to define a set of exhaustive types, and are closely related to
int
int
s.
but what does it mean to have
IEnumerable<string>
IEnumerable<string>
and how different is it from
string[]
string[]
?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Difference between string and string?
C#CC# / help
8mo ago
Difference between String and string keyword [Answered]
C#CC# / help
4y ago
❔ Difference string and string?
C#CC# / help
3y ago