Sum and Concat Operator operators in Linq.

Linq contains lots useful operators and i have found more two operators that can be help full in our day to day programming life.  Here are explanation.

Concat Operator: Concat operator concats two entities into single entities its very use full when we are doing some string operator where need to do string operations like concatenation. Here in example i have taken two arrays and concat into single entity.

Sum Operator: When we are developing application like shopping cart and other stuff this operator can be use full where we need to calculate the total or order price and other stuff you can apply this operator array, list and anything that implemented IEnumerable interface. Here i have taken a integer array for the example.

Here is the code for both operators.

C#, using GeSHi 1.0.8.8
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6.  
  7. namespace ConsoleApplication1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] a = { "a", "b", "c", "d" };
  14.             string[] b = { "d","e","f","g"};
  15.            
  16.  
  17.             Console.WriteLine("Concat Example");
  18.             var CtResult = a.Concat<string>(b); 
  19.             foreach (string s in CtResult)
  20.             {
  21.                 Console.WriteLine(s);
  22.             }
  23.  
  24.             int[] num = { 1, 2, 3, 4, 5 };
  25.             Console.WriteLine("\n\n\nSum Example");
  26.             var SumResult = num.Sum();
  27.             Console.WriteLine(SumResult);
  28.             Console.ReadKey(); 
  29.         }
  30.     
  31.     }
  32. }
Parsed in 0.018 seconds at 41.68 KB/s

And here is the output of console application as expected.

LinqOperators

Hope this will help you..

Technorati Tags: ,,,
Shout it
Published Saturday, June 19, 2010 2:19 PM by Jalpesh P. Vadgama
Filed under: , ,

Comments

# Twitter Trackbacks for Sum and Concat Operator operators in Linq. - DotNetJaps [asp.net] on Topsy.com

Pingback from  Twitter Trackbacks for                 Sum and Concat Operator operators in Linq. - DotNetJaps         [asp.net]        on Topsy.com

# Tata, Future Group launch GSM mobile service | Custom oil painting

Pingback from  Tata, Future Group launch GSM mobile service | Custom oil painting

# Twitter Search Science: Advanced Operators For Marketing Ninja &#8230; | Newest Trends on the Internet

Pingback from  Twitter Search Science: Advanced Operators For Marketing Ninja &#8230; | Newest Trends on the Internet

# Tata, Future Group launch GSM mobile service | SEM??????

Pingback from  Tata, Future Group launch GSM mobile service | SEM??????

# I&#8217;m creating a new forum management and live chat operator services website and i need help with the homepage! | Custom oil painting

Pingback from  I&#8217;m creating a new forum management and live chat operator services website and i need help with the homepage! | Custom oil painting

# Rush Enterprises to sell John Deere equipment unit | SEM??????

Pingback from  Rush Enterprises to sell John Deere equipment unit | SEM??????

# Day Care Operator Arrested for Prostitution | Custom oil painting

Pingback from  Day Care Operator Arrested for Prostitution | Custom oil painting

# I would like to know which telecom operators are working on &#8220;Identity management service&#8221; other than Orange. | Custom oil painting

Pingback from  I would like to know which telecom operators are working on &#8220;Identity management service&#8221; other than Orange. | Custom oil painting

# How do Hotel wake up call services work? | Custom oil painting

Pingback from  How do Hotel wake up call services work? | Custom oil painting

# re: Sum and Concat Operator operators in Linq.

Thursday, September 23, 2010 3:56 PM by Jun

So that's how those things work? Wow, I had no idea. But now I am fully aware, thanks for sharing!

Leave a Comment

(required) 
(required) 
(optional)
(required)