xxxxxxxxxx
string[] myArray = {"Dogs", "Cats", "Birds"};
foreach (string item in myArray)
{
Console.WriteLine(item);
}
xxxxxxxxxx
int[] arr = new int[9]; //initialize the array, now it's [null,null,null,...];
for (int i = 0; i < arr.Length; i++)
{
Random rnd = new Random();
arr[i] =rnd.Next(0, 1001);
}
for (int i = 0; i < arr.Length; i++) // print a random arr, ^
{
Console.Write(", "+ arr[i]);
}
xxxxxxxxxx
foreach(var item in yourArray)
{
Console.WriteLine(item.ToString());
}
xxxxxxxxxx
using System;
namespace print_string_array
{
class Program
{
static void Main(string[] args)
{
string[] arr = new string[] { "one", "two", "three", "four" };
Console.WriteLine(String.Join("\n", arr));
}
}
}
xxxxxxxxxx
// Sample program to print an array in C#
using System;
class Program
{
static void Main(string[] args)
{
// Create an array with some elements
int[] numbers = { 2, 4, 6, 8, 10 };
// Print each element of the array
foreach (int num in numbers)
{
Console.WriteLine(num);
}
}
}