सबसे पहले, सरणी सेट करें -
int[] p = new int[] {55, 66, 88, 99, 111, 122, 133};
अब, मान लें कि आपको स्थिति 1 पर एक तत्व सेट करने की आवश्यकता है -
p[2] = 77;
आइए देखें पूरा कोड -
उदाहरण
using System; namespace Program { public class Demo { public static void Main(string[] args) { int[] p = new int[] {55, 66, 88, 99, 111, 122, 133}; int j; Console.WriteLine("Initial Array......"); for (j = 0; j < p.Length; j++ ) { Console.WriteLine("arr[j] = {0}", p[j]); } // set new element at index 2 p[2] = 77; Console.WriteLine("New Array......"); for (j = 0; j < p.Length; j++ ) { Console.WriteLine("arr[j] = {0}", p[j]); } } } }
आउटपुट
Initial Array...... arr[j] = 55 arr[j] = 66 arr[j] = 88 arr[j] = 99 arr[j] = 111 arr[j] = 122 arr[j] = 133 New Array...... arr[j] = 55 arr[j] = 66 arr[j] = 77 arr[j] = 99 arr[j] = 111 arr[j] = 122 arr[j] = 133