SetValue () विधि एक-आयामी सरणी में निर्दिष्ट स्थान पर तत्व के लिए एक मान सेट करती है। अनुक्रमणिका को 32-बिट पूर्णांक के रूप में निर्दिष्ट किया गया है।
सबसे पहले, सरणी सेट करें।
Array arr = Array.CreateInstance(typeof(String), 6);
SetValue() विधि का उपयोग करने वाले तत्व के लिए कोई सेट मान नहीं है।
arr.SetValue("One", 0);
arr.SetValue("Two", 1);
arr.SetValue("Three", 3);
arr.SetValue("Four", 4);
arr.SetValue("Five", 5); C# में SetValue () पद्धति के उपयोग को दर्शाने वाला एक उदाहरण निम्नलिखित है।
उदाहरण
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Demo {
class Program {
static void Main(string[] args) {
Array arr = Array.CreateInstance(typeof(String), 6);
arr.SetValue("One", 0);
arr.SetValue("Two", 1);
arr.SetValue("Three", 3);
arr.SetValue("Four", 4);
arr.SetValue("Five", 5);
Console.WriteLine("Length {0}",arr.GetLength(0).ToString());
Console.ReadLine();
}
}
} आउटपुट
Length 6