C# ??? C#.net ?? 4.0? ??? ??? ?????. ?? ??? ??? ??? ??? ??? ??? ????? ???????. ??? Out ????, ??? ?? ??? ?? ?? ?? ?? ??? ?? ?? ??? ?? ?? ????? ??? ????? ?? ?? ???? ? ??? ???. ????? ?? ??? ??? ????? ? ??? ??? ?? ????? ??? ??? ??? ? ????.
C# ??? ??? ??? ??????
??? ? ?? ???? ??? ? ????
1. ??? ??
??? ???? ?? ???? Tuple
?? ?? ??
Tuple <T1> (T1)
?:
Tuple<int> Tuple_example = new Tuple<int>(27); Console.WriteLine(Tuple_example); Console.ReadLine();
??:
?? ?? ??
Tuple <T1, T2> (T1, T2)
?:
Tuple<int, string, bool> tuple = new Tuple<int, string, bool>(1, "cat", true); Console.WriteLine(tuple.Item1); Console.WriteLine(tuple.Item2.ToString()); Console.ReadLine();
??:
2. ?? ??
C#??? ??? ?? ??? ???? ?? Create ???? ?????
?? ?? ??
Create (T1);
?:
var Tuple_example = Tuple.Create(27); Console.WriteLine(Tuple_example); Console.ReadLine();
??:
?? ?? ??
Create (T1, T2);
?:
var Tuple_example = Tuple.Create(1, "cat", true); Console.WriteLine(Tuple_example.Item1); Console.WriteLine(Tuple_example.Item2.ToString()); Console.ReadLine();
??:
???? ???? ?? ??? ???? ?? ?? ??? ??? ??? ???? ???. Create ???? ?? ?? ???? ??? ???? ? ??? ???.
???
?? ??? ?? ?????. ?, ?? ?? ???? ??? ? ?? ???? ?? ??? ?? ???. C#7.0??? ?? ??? ?? ??? ??? ??? Tuple? ???? ??? ValueTuple? ??????. ValueTuple? ?? ??? ? ?? ?? ?????. ? ??? .NET Framework 4.7 ?? .NET ????? 2.0? ?? ?????. ?? ??? ??? ????? System.Value.Tuple??? NuGet ???? ???? ???.
ValueTuple ????
- ValueTuple? ??? ?? ????
?:
var Tuple_example = (1, "cat", true); Console.WriteLine(Tuple_example.Item1); Console.WriteLine(Tuple_example.Item2.ToString()); Console.ReadLine();
??:
??? ????.
var Tuple_example = Tuple.Create(1, "cat", true); Console.WriteLine(Tuple_example.Item1); Console.WriteLine(Tuple_example.Item2.ToString()); Console.ReadLine();
- 'var' ???? ???? ??? ValueTuple? ??? ?? ????. ? ?? ? ??? ??? ??? ???? ???
?:
(int, string, bool) Tuple_example = (1, "cat", true); Console.WriteLine(Tuple_example.Item1); Console.WriteLine(Tuple_example.Item2.ToString()); Console.ReadLine();
??:
- ? ???? ValueTuple?? ?? ??? ? ????.
?:
details.Item1;?? – returns 28 details.Item2; -- returns ”CBC”
- ValueTuple? ?? ??? ?? ??? ??? ??? ? ????.
?:
var detail = (28);? --this is not a tuple var details = (28, “CBC”); -- this is a tuple
? ?? ????? ????? 'detail'? ??? ???? ?? ?? ???? 'var' ???? ?????.
- ValueTuple? 7?? ??? ?? ??? ??? ?? ?? 8? ??? ?? ??? ? ????.
- ValueTuple? ??? Item1, Item2 ?? ?? ??? ?? ? ????.
(int ID, String Firstname, string SecondName) details = (28, “CBC”, “C# Tuples”);
- ?????? ??? ?? ValueTuples? ??? ????? ??? ?? ????. ?? ??? 'FirstName' ??? ??? ? ??? ? ?? ??? ? ?? ??? ???? ??? ???? ?? ???? ??? ? ????.
??? ??? ??????
- C# ?????? ??? 8?? ??? ?????. ?, 0?? 7??? ?? ?? ? ???, ? ??? ??? ??? ????? ?? ?? ?? TRest? ?? ??? ?????.
var nestedtuple_example = new Tuple <int, string, string, int, int, int, string, Tuple<double, int, string>> (5, “This”, “is”, 7,8,9, “number”, Tuple.Create (17.33, 29,”April”));
- ??? ? ?? ??? ??? ???? 'out' ? 'ref' ???? ???? ?? ?? ???? ???? ???? ????. 'Out' ? 'ref' ????? ??? ??? ????? ? ???, 'out' ? 'ref' ????? 'asnyc' ???? ?? ???? ????. ?? ?? public void TupleExampleMethod(Tuple
tupleexample)
{ Var multiplication = tupleexample.Item1 * tupleexample.Item2; Console.WriteLine (“Multiplication is”, {0}, multiplication); }
TupleExampleMethod ???? ??? ????
TupleExampleMethod(new Tuple<int, int> (34,56));
- The dynamic keyword can also be used to return values from any method, but it is seldom used due to performance issues. The returning of the tuple from a method.
public static Tuple <int, string> GetPerson() { return Tuple.Create (1, “abc”); }
Let’s create a program in Visual to understand how tuple works.
- Launch Visual Studio and create a windows project.
- We are creating a simple multiplication program that shows passing tuples by a method. A sample window created as below.
The values from both textboxes are taken into a tuple and the tuple is passed on to a method.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnMultiply_Click(object sender, EventArgs e) { int value1 = Convert.ToInt32(txtVal1.Text); int value2 = Convert.ToInt32(TxtVal2.Text); CallMethod(new Tuple<int, int>(value1, value2)); } private void CallMethod(Tuple<int, int> tuple) { txtResult.Text = Convert.ToString(tuple.Item1 * tuple.Item2); Console.ReadLine(); } } }
The result is displayed in the third text box named as txtResult. End result looks like.
Conclusion
The tuple data structure is a reference type, which means the values are stored on the heap instead of stack. This makes usage of tuples and accessing them in the program an intensive CPU task. The only 8 elements in tuples property is one of the major drawbacks of tuples as nested tuples are more prone to induce ambiguity. Also accessing elements in tuple with Item
? ??? C# ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? ??











C#? ?? ??? ??????. ???? ?? ???? ?? ??, ?? ?? ? ?? ??? ??? ?? ?????.

?? ???? ????? ???? ?? ???? ??? ?? ???? ???? ??, ?? ???? ???? ?? ?????? ??? ????? ????. ?? ???? ??? ??? ? ??? ???? ????? ??? ?? ??? ?????. ?? ???? ??? ??? ??? ????? ???? ???? ??? UI ???? ???? ?? ????. ?? ??? ?? ????? ???? ?? ??? ??? ?? ????. ?? ??? ??? ?? ???? ???? ?? ???? ?? ???? UI ?? ?? ?????? ?? ???? ??? ?????.

C#? C? ??? ??? ???? ??? ??? ????. 1.C? 1983 ? Bjarnestroustrup? ?? ???? ?? ?? ?????? C ??? ??????. Evolution ?????? ?? ??? ?? ? Lambda Expressions ?? C 11, C 20 ?? ?? ? ? ??? ?? ?? ???? ???? ?? ?? ? ??? ?? ?????? ??? ? ????. 2.C#? 2000 ? Microsoft? ?? ?????? C? Java? ??? ???? ??? ???? ???? ??? ???. ?? ??, C#2.0? ???? C#5.0 ?? ? ??? ?????? ?????, ?? ?? ???? ??? ? ???? ???? ??? ? ????.

XML ??? ???? ???? ?? ??? ????. Notepad? ?? ??? ???? ???? ??; XMLBeautifier? ?? ??? ?? ???? XML ?? ??? ?? ??; XSLT? ?? XML ?? ??? ???? ?? ??? ?????. ?? Python? ?? ????? ??? ???? ?? ???? ?????. ?? ??? ???? ?? ? ???????.

C#? Palindrome ??????. ???? C#? ?? ?? ?? ??? ??? ??? ?? ??? ??? ?? ?????.
