Answers for "How to make a array in c#"

C#
29

c# initialize array

string[] stringArray = new string[6];
//or
int[] array1 = new int[] { 1, 3, 5, 7, 9 };
//
string[] weekDays = new string[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
//etc
Posted by: Guest on April-02-2020
67

c# array

int[] array = new int[]{1, 2, 3, 4, 5};
foreach (string i in array) 
{
  Console.WriteLine(i);
}

//or

for(int i=0; i<array.Length; i++){
	  Console.WriteLine(array[i]);
}
Posted by: Guest on February-20-2020
18

c# create array

// Define and Initialize
int[] arr = {1, 2, 3};

// Buuuut:
// Initial defining
int[] arr;

// This works
arr = new int[] {1, 2, 3};   

// This will cause an error
// arr = {1, 2, 3};
Posted by: Guest on March-04-2020
5

array in C#

// String array for my friends ( Example )
string[] myFriends = {"Friend1", "Friend2", "Friend3", "Friend4"};

// Display MyFriend2 at index of ( 1 )
Console.WriteLine(myFriends[1]);
Posted by: Guest on June-05-2021
4

array syntax c#

class TestArraysClass
{
    static void Main()
    {
        // Declare a single-dimensional array of 5 integers.
        int[] array1 = new int[5];

        // Declare and set array element values.
        int[] array2 = new int[] { 1, 3, 5, 7, 9 };

        // Alternative syntax.
        int[] array3 = { 1, 2, 3, 4, 5, 6 };

        // Declare a two dimensional array.
        int[,] multiDimensionalArray1 = new int[2, 3];

        // Declare and set array element values.
        int[,] multiDimensionalArray2 = { { 1, 2, 3 }, { 4, 5, 6 } };

        // Declare a jagged array.
        int[][] jaggedArray = new int[6][];

        // Set the values of the first array in the jagged array structure.
        jaggedArray[0] = new int[4] { 1, 2, 3, 4 };
    }
}
Posted by: Guest on May-15-2020
3

How to make a array in c#

//use this for unity editor:
using UnityEngine;

public class MyScript : MonoBehaviour {
//You can change the variable type to int, float, strings and others
//Note: You need to asign the objects from the unity editor or the script
  
    public GameObject[] MyObjects;/*edit the size of the array in the unity editor
  								  or add = new GameObject[the length of the array]*/

    void Update(){
    //Here we are using for loop to destroy our objects in the list
        for (int i = 0; i < MyObjects.Length; i++){
            Destroy(MyObjects[i], 3.0f);/*The second parameter is how much seconds to wait 
            							before the certain object will be destroyed*/
        }
    }
}
//Sry for my english its bad
Posted by: Guest on June-09-2021

C# Answers by Framework

Browse Popular Code Answers by Language