class Demo
{
static void Main()
{
string[] colors = { "red", "green", "blue", "yellow" };
// case 1. array to IEnumerable<string>
IEnumerable<string> values = colors;
foreach (var color in values)
{
Console.Write(color + " ");
}
// case 2. Array to List
List<string> items = colors.ToList();
items.Add("orange");
Console.WriteLine(items.Count);
foreach (var item in items)
{
Console.Write(item + " ");
}
// case 3. IEnumerable<string> to array
var moreColors = items.ToArray();
Console.WriteLine(moreColors.Length);
foreach (var item in moreColors)
{
Console.Write(item + " ");
}
}
}
Tuesday, June 16, 2026
C# Conversions between Array, List and IEnumerable
Example
Subscribe to:
Post Comments (Atom)
Hot Topics
-
In previous post , we learnt basic introduction to SQL Server . In this post we will learn about SSMS (SQL Server Management Studio) softwar...
-
In the previous post we have learnt about SSMS (SQL Server Management Studio) and how to connect with a SQL Server instance. In this post w...
-
By Ajeet Kumar RADAR CHART In radar chart, the categorical variable is displayed as spikes radiating from a central point. The values o...
No comments:
Post a Comment