ScreencastADay
Watch and Learn!
Home
Introduction to Extension Methods
9/17/2008 8:00:00 PM size => 5.27 MB, duration => 7:24
Extension Methods are introduced in C# 3.0. Extension Methods are used to extend the behavior of the classes using methods.
Customer customer = new Customer() { FirstName = "Mohammad", LastName = "Azam" };
Console.WriteLine(customer.ToJSON());
public static class ExtensionMethods
{
public static string ToJSON<T>(this T item) where T : BusinessBase
{
JavaScriptSerializer js = new JavaScriptSerializer();
return js.Serialize(item);
}
public static bool IsPrimeNumber(this int no)
{
bool isPrime = true;
if (no == 2) return false;
for (int i = 2; i < no; i++)
{
if (no % i == 0)
{
isPrime = false;
break;
}
}
return isPrime;
}
}
Double Click on the Video to Enlarge
Comments
Name
Email
Comment/Feedback
Categories
C# (16)
ASP.NET (36)
JavaScript (19)
Ruby (3)
SQL (2)
Unit Testing (12)
Architecture (6)
Ajax (5)
WPF (2)
Visual Studio (2)
Cool Tools (1)
Calendar
September 2008
M
T
W
T
F
S
S
« Jul
Sep »
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Lorem Ipsum Dolor
Nulla luctus eleifend purus
Praesent scelerisque scelerisque erat
Ut nonummy rutrum sem
Pellentesque tempus quam quis nulla
Fusce ultrices fringilla metus
Praesent mattis condimentum nisl