string[] myArray = {"Dogs", "Cats", "Birds"};
foreach (string item in myArray)
{
Console.WriteLine(item);
}
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]);
}
Console.WriteLine(string.Join("
", myArrayOfObjects));
//array of numbers, it works with strings also
int numbers[3] = {1, 4, 5, 6}
/*declares int named 'number' and assigns it the value of an index
starting from index 0 to the end of the array, in this case, 3*/
foreach(int number in numbers){
//prints the number
Console.WriteLine(number);
}
foreach(var item in yourArray)
{
Console.WriteLine(item.ToString());
}
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("
", arr));
}
}
}
using System.Linq;
namespace Program
{
public class Program
{
string[] cLangs = { "Langs","C", "C++", "C#" };
// String join will just join the array with a comma and a whitespace
// Using Linq, the skip method will skip x (called count in the parameter) number elements you tell it to
Console.WriteLine(string.Join(", ", cLangs.Skip(1).ToArray())); // Output: C, C++, C#
}
}