Tuple
এটি −
-এ ব্যবহৃত হয়- একটি ডেটা সেটে সহজে অ্যাক্সেস।
- ডেটা সেটের সহজে হেরফের।
- ডেটার একটি একক সেট প্রতিনিধিত্ব করতে।
- একটি পদ্ধতি থেকে একাধিক মান ফেরত দিতে
- একটি পদ্ধতিতে একাধিক মান পাস করতে
এর চারটি বৈশিষ্ট্য রয়েছে -
-
আইটেম1৷ − বর্তমান Tuple
অবজেক্টের প্রথম উপাদানটির মান পান৷ -
আইটেম2৷ − বর্তমান Tuple
বস্তুর দ্বিতীয় উপাদানের মান পান৷ -
আইটেম3৷ − বর্তমান Tuple
অবজেক্টের তৃতীয় উপাদানের মান পান। -
আইটেম4৷ − বর্তমান Tuple
বস্তুর চতুর্থ উপাদানের মান পান৷
উদাহরণ
আসুন এখন C# −
-এ 4-টুপল বাস্তবায়নের একটি উদাহরণ দেখিusing System;
public class Demo {
public static void Main(string[] args) {
Tuple<string,string,string,string> tuple = new Tuple<string,string,string,string>("nathan", "steve", "katie", "tim");
Console.WriteLine("Value (Item1)= " + tuple.Item1);
Console.WriteLine("Value (Item2)= " + tuple.Item2);
Console.WriteLine("Value (Item3)= " + tuple.Item3);
Console.WriteLine("Value (Item4)= " + tuple.Item4);
if (tuple.Item1 == "nathan") {
Console.WriteLine("Exists: Tuple Value = " +tuple.Item1);
}
if (tuple.Item2 == "jack") {
Console.WriteLine("Exists: Tuple Value = " +tuple.Item2);
}
if (tuple.Item3 == "katie") {
Console.WriteLine("Exists: Tuple Value = " +tuple.Item3);
}
if (tuple.Item4 == "tom") {
Console.WriteLine("Exists: Tuple Value = " +tuple.Item4);
}
}
} আউটপুট
এটি নিম্নলিখিত আউটপুট −
তৈরি করবেValue (Item1)= nathan Value (Item2)= steve Value (Item3)= katie Value Value (Item4)= tom Exists: Tuple Value = nathan Exists: Tuple Value = katie
উদাহরণ
এখন C# −
-এ 4-টুপল প্রয়োগ করার জন্য আরেকটি উদাহরণ দেখা যাকusing System;
public class Demo {
public static void Main(string[] args) {
Tuple<int,int,int,int> tuple = new Tuple<int,int,int,int>(100, 150, 300, 450);
Console.WriteLine("Value (Item1)= " + tuple.Item1);
Console.WriteLine("Value (Item2)= " + tuple.Item2);
Console.WriteLine("Value (Item3)= " + tuple.Item3);
Console.WriteLine("Value (Item4)= " + tuple.Item4);
if (tuple.Item1 == 100) {
Console.WriteLine("Exists: Tuple Item 1 = " +tuple.Item1);
}
if (tuple.Item2 == 250) {
Console.WriteLine("Exists: Tuple Item 2 = " +tuple.Item2);
}
if (tuple.Item3 == 270) {
Console.WriteLine("Exists: Tuple Item 3 = " +tuple.Item3);
}
if (tuple.Item4 == 300) {
Console.WriteLine("Exists: Tuple Item 4 = " +tuple.Item4);
}
}
} আউটপুট
এটি নিম্নলিখিত আউটপুট −
তৈরি করবেValue (Item1)= 100 Value (Item2)= 150 Value (Item3)= 300 Value (Item4)= 450 Exists: Tuple Item 1 = 100