Friday, April 20, 2012

File Upload in ASP.NET MVC3

If you are a web developer you often need to upload file on the web server or database. In today’s post I am going explain how we can upload file in ASP.NET MVC 3 with razor syntax.

So, first thing we need to create a view that will contain the file upload control. I am going to use an existing asp.net mvc template for this demo. So I have just modified the default Index view like following.
Share:
Tuesday, April 17, 2012

Difference between SkipWhile and Where in linq

Before some time I have written a blog post about the SkipWhile operator and a reader of my blog asked me that we can do the same thing with Where also but there is a difference between this two. So In this post I am going to explain you difference between those two.

Where operator filters a list of collection based on condition. It will filter whole collection while SkipWhile will only skip those elements in list until condition is true and after that it will stop filtering of skipping.Now let’s take an example where we can see the difference between Where and SkipWhile. Following is a code for that.
Share:
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:

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