Guruji Point - Code You Want To Write

  • Home
  • Asp.Net
  • WCF
  • SQL
  • Type Script
  • AngularJS
  • Tech News
  • Blog
  • Earn Online

Monday, 10 April 2017

Tuple in Asp.Net C#

 asp.net, pass multiple values in single parameter, service, Tuples, Tuples in c#, why tuple used     No comments   


Introduction
In this post we will learn what is tuple and how to use tuple using c#. Why do we need to use tuple in which situations .

What is
This Tuple concept comes in c# 4.0. In C#, tuples are used to store data. It’s just like a variable, but in order for it to be a tuple it must contain more than one value. Each instance of a tuple has a fixed number of items within it (and each item has its own distinct type, eg. a variable or an int), 

At the time of Tuple creation we define the order of element in a Tuple. Tuples have all read only properties means we can not change them once created. Tuple size is fixed and cannot change after declaration.

Why Tuple
Using Tuple without the use of out parameter we can return a dataset from class method.
Using Tuple we can pass multiple values by using a single parameter.

Tuple Class
Tuple class is static. We can access all the tuple class method without creating object of this class. Tuple class have 8 overloaded create methods.


Tuple.Create<t1>
 
Tuple.Create<t1, t2>
 
Tuple.Create<t1, t2, t3>
 
Tuple.Create<t1, t2, t3, t4>
 
Tuple.Create<t1, t2, t3, t4, t5>
 
Tuple.Create<t1, t2, t3, t4, t5, t6>
 
Tuple.Create<t1, t2, t3, t4, t5, t6, t7>
 
Tuple.Create<t1, t2, t3, t4, t5, t6, t7, t8>


Practice 
By using tuple class constructor we can create the object of tuple.

Tuple<int, bool, string> tuple = new Tuple<int, bool, string>                                        (101, true, "JP");


Here i am sharing my tested code for tuples better explanation and understanding.
public void TupleMethodEx(Tuple<string, string, int> tupleParameter)
    {
        var testTuple = tupleParameter;
        Console.WriteLine("Name:{0}, Address:{1}, Phone:{2}.",
        testTuple.Item1, testTuple.Item2, testTuple.Item3);
    }


Call this method and pass Tuple type parameter.


TestTupleClass objTuple = new TestTupleClass();
objTuple.TupleMethodEx(new Tuple<string, string, int>
                                       ("Jack", "California", 0767876765));
 
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Facebook Updates

Guruji Point

Categories

Comman table Expression in SQL Dynamic Grid Row IQueryable in c# Learn AngularJS Scope_Identity() Use of indexes comma seperated string in sql row_number() and dense_rank() salary table structure. while loop in sql why do we need cursor why tuple used

About Us

This blog is about the Programming ,Tech News and some intresting facts related Contents. Here you can find fundamental and expert level topic of programming languages very practically related to C# , Asp.Net ,Sql-Server, JavaScript, Jquery, WebServices And also Web-Api, WCF ,WPF, Angular Js.

Contact Us

Email Us - gurujipoints@gmail.com
Contact- 8077657477

Reach Us

Copyright © Guruji Point - Code You Want To Write