একই ভেরিয়েবলে একাধিক মান সেট করতে C#-এ অ্যারে (arrays) ব্যবহার করুন। ধরুন ৫টি ভেরিয়েবল নেওয়ার বদলে, অ্যারে ব্যবহার করে ৫টি মান একটি ভেরিয়েবলে রাখুন।
৩টি মান একটি স্ট্রিং অ্যারে-এ একটি ভেরিয়েবলে সেট করার উদাহরণ:
string[] arr = new string[3];
এখন ইনিশিয়ালাইজ করুন:
string[] arr = new string[3] {"one", "two", "three"};
সম্পূর্ণ উদাহরণ
using System;
public class Demo {
static void Main(string[] args) {
string[] arr = new string[3] {"one", "two", "three"};
for (int i = 0; i < arr.Length; i++) {
Console.WriteLine("Values: " + arr[i]);
}
Console.ReadKey();
}
}
আউটপুট
Values: one Values: two Values: three