Monday, April 16, 2012

Tuple in C# 4.0

C# 4.0 language includes a new feature called Tuple. Tuple provides us a way of grouping elements of different data type. That enables us to use it a lots places at practical world like we can store a coordinates of graphs etc.

In C# 4.0 we can create Tuple with Create method. This Create method offer 8 overload like following. So you can group maximum 8 data types with a Tuple. Followings are overloads of a data type.
  • Create(T1)- Which represents a tuple of size 1
  • Create(T1,T2)- Which represents a tuple of size 2
  • Create(T1,T2,T3) – Which represents a tuple of size 3
  • Create(T1,T2,T3,T4) – Which represents a tuple of size 4
  • Create(T1,T2,T3,T4,T5) – Which represents a tuple of size 5
  • Create(T1,T2,T3,T4,T5,T6) – Which represents a tuple of size 6
  • Create(T1,T2,T3,T4,T5,T6,T7) – Which represents a tuple of size 7
  • Create(T1,T2,T3,T4,T5,T6,T7,T8) – Which represents a tuple of size 8
Share:
Saturday, April 14, 2012

TakeWhile operator in linq

In this post I am going to explain TakeWhile Operator in details. TakeWhile is one of partitioning operator available in Linq. It will take sequence until condition becomes false.

Here is the example for that.

using System;
using System.Collections.Generic;
using System.Linq;
namespace Linq
{
class Program
{
  static void Main(string[] args)
  {
      int[] numbers ={10,9,8,7,6,5,4,3,2,1};

      foreach(var number in numbers.TakeWhile(n=>n>5))
      {
          Console.WriteLine(number);
      }
  }
}
}


Share:

SkipWhile Method in Linq

I have been playing around linq and I have found great method call SkipWhile method. SkipWhile methods skips particular element which matches condition in predicate this can be use full in condition where we need to skip elements on particular condition.

So let’s take some example. I have written following console application code.

using System;
using System.Collections.Generic;
using System.Linq;
namespace Linq
{
  class Program
  {
      static void Main(string[] args)
      {
          string[] names = { "Jalpesh", "Jayesh", "Tushar", "Tejas", "Sanjay", "Nijesh" };
          foreach(var name in names.SkipWhile(s=>s.ToLower().StartsWith("j")))
          {
              Console.WriteLine(name);
          }
      }
  }
}

Share:

Full screen in Visual studio 2010

Visual studio is a great IDE and I am learning everyday something new and I have found one great feature today which is available from the Visual studio 2008. So I thought it would great to be share with all you guys.

We all like to have most portion of screen to cover code part so we can view all the lines and we don’t have to use page and page down keys to navigate through code. You can have visual studio in full screen mode with View->Full Screen or via pressing Shift + Alter + Enter as shortcut..
Share:
Friday, April 13, 2012

Multicast delegates in c#

In yesterday’s post We learn about Delegates and how we can use delegates in C#. In today’s blog post we are going to learn about Multicast delegates.

What is Multicast Delegates?

As we all know we can assign methods as object to delegate and later on we can call that method with the help delegates. We can also assign more then methods to delegates that is called Multicast delegates. It’s provide functionality to execute more then method at a time. It’s maintain delegates as invocation list (linked list).
Share:
Thursday, April 12, 2012

Delegates in c#

I have used delegates in my programming since C# 2.0. But I have seen there are lots of confusion going on with delegates so I have decided to blog about it. In this blog I will explain about delegate basics and use of delegates in C#.

What is delegate?

We can say a delegate is a type safe function pointer which holds methods reference in object. As per MSDN it's a type that references to a method. So you can assign more than one methods to delegates with same parameter and same return type.
Share:
Wednesday, April 11, 2012

Dynamically creating meta tags in asp.net mvc

As we all know that Meta tag has very important roles in Search engine optimization and if we want to have out site listed with good ranking on search engines then we have to put meta tags. Before some time I have blogged about dynamically creating meta tags in asp.net 2.0/3.5 sites, in this blog post I am going to explain how we can create a meta tag dynamically very easily.

To have meta tag dynamically we have to create a meta tag on server-side. So I have created a method like following.

Share:

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews