Answers for "define an array in c#"

C#
1

Defining a new array with elements in c#

int [] marks = new int[]  { 99,  98, 92, 97, 95};
Posted by: Guest on June-17-2021
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