This is a mirror of official site: http://jasper-net.blogspot.com/

An introduction to Tuple

| Wednesday, October 27, 2010
Introduction

C#4.0 has introduce a new feature call Tuple.

Definition
   In mathematics and computer science, a tuple is an ordered list of elements. In set theory, an (ordered) n-tuple is a sequence (or ordered list) of n elements, where n is a positive integer. There is also one 0-tuple, an empty sequence. (From Wikipedia)

Purpose: Some time we need to return more than one value from a method or function.

Using the code

Let us perform a simple experiment for the basic arithmetic operations for the concept to understand. Let us first write our Calculate Function

///
/// Calculate
private void Calculate(out int add, out int sub,out int mul,out int div)
{
  int num1 = 5;
  int num2 = 4;
  add = num1 + num2;
  sub = num1 - num2;
  mul = num1 * num2;
  div = num1 / num2;
}

Older approach (Till dotnet 3.5)

Approach 1: Using OUT parameter

Read more: Codeproject

Posted via email from .NET Info

0 comments: