New Features in C# 4.0

Posted on Updated on

Visual Studio 2010 is packed with new and enhanced features that simplify the entire development process from design to deployment. Customize your workspace with multiple monitor support. Create rich applications for SharePoint and the Web. Target multiple versions of the .NET Framework with the same tool. Eliminate the dreaded “no repro” problem with IntelliTrace. And much more.

Visual Studio 2010 is here!And of course this means that C# 4.0 is also here. Let’s do a quick review of the new language features added in this release.


The dynamic keyword is a key feature of this release. It closes the gap between dynamic and statically-typed languages. Now you can create dynamic objects and let their types be determined at run time. With the addition of the System.Dynamicnamespace, you can create expandable objects and advanced class wrappers, and you can provide interoperability between different languages, including dynamic ones. Here is one quick example:

dynamic contact = new ExpandoObject();

contact.Name = “Patrick Hines”;

contact.Phone = “206-555-0144”;

Covariance and Contravariance

Variance on generic type parameters in interfaces and delegates is another important feature of this release. It doesn’t add much new functionality, but rather makes things work as you expected them to in the first place. The major advantage is hidden in this simple line, which didn’t compile until C# 4.0:

IEnumerable<Object> objects = new List<String>();
The ability to implicitly convert references for objects instantiated with different type arguments makes it much easier to reuse code. Read the Covariance and Contravariance FAQ to learn more about this feature.

Optional (or Default) Parameters

People have been asking for this feature since C# 1.0. Three versions later, it’s finally here.

Now you can assign a default value to a parameter right within the method declaration. The user of the method can either pass a value or simply skip the argument. In the latter case, the default value is passed to the method.

Method declaration:

public static void SomeMethod(int optional = 0) { }

Method calls:
SomeMethod(); // 0 is used in the method.


Named Arguments

The order of parameters in a method declaration and the order of arguments you pass when calling the method don’t need to match anymore. You can provide arguments in any order you like by specifying parameter names in a method call. This might also improve the readability of your code.

var sample = new List<String>();

sample.InsertRange(collection: new List<String>(), index: 0);

sample.InsertRange(index: 0, collection: new List<String>());

Read more about optional parameters and named arguments on MSDN.

Improved COM Interop

The introduction of the dynamic keyword, optional parameters and named arguments enables improvement of COM interop. So, no more ugly code like this:

var excelApp = new Excel.Application();

// . . .

excelApp.get_Range(“A1”, “B4”).AutoFormat(


Type.Missing, Type.Missing, Type.Missing,

Type.Missing, Type.Missing, Type.Missing);

You can now simply write the following:

excelApp.Range[“A1”, “B3”].AutoFormat(


By the way, this code uses one more new feature: indexed properties (take a closer look at those square brackets after Range.) But this feature is available only for COM interop; you cannot create your own indexed properties in C# 4.0. For more information about new COM interop features, once again, refer to MSDN.

What Else?

Of course, C# benefits not only from new language features, but also from improvements to its integrated development environment (IDE) and to the .NET Framework.

Here are some links for further reading:

Happy coding
free counters


Date Formatting in C#

Posted on

Hello all.

hope doing well …

here is another tip related to C# programming …. i found it useful so sharing with you people …   this is how you can format date in different format in asp.net / C#

the usage is as follows

<%= String.Format(“{specifier}”, DateTime.Now) %>

where the possible specifiers are given below.

Specifier Description Output
d Short Date 15/05/2010
D Long Date 15 June 2010
t Short Time 21:08
T Long Time 21:08:59
f Full date and time 15 June 2010 21:08
F Full date and time (long) 15 June 2010 21:08:59
g Default date and time 15/06/2010 21:08
G Default date and time (long) 15/06/2010 21:08:59
M Day / Month 15 June
r RFC1123 date Tue, 15 June 2010 21:08:59 GMT
s Sortable date/time 2010-06-15 21:08:59
u Universal time, local timezone 2010-06-15 21:08:59Z
Y Month / Year June 2010
dd Day 15
ddd Short Day Name Sun
dddd Full Day Name Sunday
hh 2 digit hour 09
HH 2 digit hour (24 hour) 21
mm 2 digit minute 08
MM Month 04
MMM Short Month name Jun
MMMM Month name June
ss seconds 59
yy 2 digit year 07
yyyy 4 digit year 2010
: seperator, e.g. {0:hh:mm:ss} 09:08:59
/ seperator, e.g. {0:dd/MM/yyyy} 15/06/2010

happy development 🙂

free counters

C# Color Names And Codes

Posted on Updated on

Last night i was working on a project of C# and required some color schemes for row color of a grid, and first time i got familiarity with System.Drawing namespace.  Its simply amazing …. really solved my many problems in just playing mode. First i use its colors and thought should share with you people. Some others features will discuss some other time..

Hear are the color codes are taken from the HTML specifications, whose names correspond to the names given for the .KnownColor attributes. For example, to get one of these color schemes, you would write

Color c = Color.FromKnownColor(KnownColor.colorname)

where colorname is from the table below. The values are also supplied; so you could use the FromArgb method to create the color. The following two lines produce the same color:

Color c1 = Color.FromArgb(32,178,170);
Color c2 = Color.FromKnownColor(KnownColor.LightSeaGreen);

In the table, I have assigned the exact color values given. The rendering you actually see will depend upon whether or not your browser honors 24-bit color requests (some browsers will map colors to the “nearest Web palette color”), the adjustments to your monitor, and the corrections your video card applies.

.AliceBlue 240,248,255 .LightSalmon 255,160,122
.AntiqueWhite 250,235,215 .LightSeaGreen 32,178,170
.Aqua 0,255,255 .LightSkyBlue 135,206,250
.Aquamarine 127,255,212 .LightSlateGray 119,136,153
.Azure 240,255,255 .LightSteelBlue 176,196,222
.eige 245,245,220 .LightYellow 255,255,224
.Bisque 255,228,196 .Lime 0,255,0
.Black 0,0,0 .LimeGreen 50,205,50
.BlanchedAlmond 255,255,205 .Linen 250,240,230
.Blue 0,0,255 .Magenta 255,0,255
.BlueViolet 138,43,226 .Maroon 128,0,0
.Brown 165,42,42 .MediumAquamarine 102,205,170
.BurlyWood 222,184,135 .MediumBlue 0,0,205
.CadetBlue 95,158,160 .MediumOrchid 186,85,211
.Chartreuse 127,255,0 .MediumPurple 147,112,219
.Chocolate 210,105,30 .MediumSeaGreen 60,179,113
.Coral 255,127,80 .MediumSlateBlue 123,104,238
.CornflowerBlue 100,149,237 .MediumSpringGreen 0,250,154
.Cornsilk 255,248,220 .MediumTurquoise 72,209,204
.Crimson 220,20,60 .MediumVioletRed 199,21,112
.Cyan 0,255,255 .MidnightBlue 25,25,112
.DarkBlue 0,0,139 .MintCream 245,255,250
.DarkCyan 0,139,139 .MistyRose 255,228,225
.DarkGoldenrod 184,134,11 .Moccasin 255,228,181
.DarkGray 169,169,169 .NavajoWhite 255,222,173
.DarkGreen 0,100,0 .Navy 0,0,128
.DarkKhaki 189,183,107 .OldLace 253,245,230
.DarkMagena 139,0,139 .Olive 128,128,0
.DarkOliveGreen 85,107,47 .OliveDrab 107,142,45
.DarkOrange 255,140,0 .Orange 255,165,0
.DarkOrchid 153,50,204 .OrangeRed 255,69,0
.DarkRed 139,0,0 .Orchid 218,112,214
.DarkSalmon 233,150,122 .PaleGoldenrod 238,232,170
.DarkSeaGreen 143,188,143 .PaleGreen 152,251,152
.DarkSlateBlue 72,61,139 .PaleTurquoise 175,238,238
.DarkSlateGray 40,79,79 .PaleVioletRed 219,112,147
.DarkTurquoise 0,206,209 .PapayaWhip 255,239,213
.DarkViolet 148,0,211 .PeachPuff 255,218,155
.DeepPink 255,20,147 .Peru 205,133,63
.DeepSkyBlue 0,191,255 .Pink 255,192,203
.DimGray 105,105,105 .Plum 221,160,221
.DodgerBlue 30,144,255 .PowderBlue 176,224,230
.Firebrick 178,34,34 .Purple 128,0,128
.FloralWhite 255,250,240 .Red 255,0,0
.ForestGreen 34,139,34 .RosyBrown 188,143,143
.Fuschia 255,0,255 .RoyalBlue 65,105,225
.Gainsboro 220,220,220 .SaddleBrown 139,69,19
.GhostWhite 248,248,255 .Salmon 250,128,114
.Gold 255,215,0 .SandyBrown 244,164,96
.Goldenrod 218,165,32 .SeaGreen 46,139,87
.Gray 128,128,128 .Seashell 255,245,238
.Green 0,128,0 .Sienna 160,82,45
.GreenYellow 173,255,47 .Silver 192,192,192
.Honeydew 240,255,240 .SkyBlue 135,206,235
.HotPink 255,105,180 .SlateBlue 106,90,205
.IndianRed 205,92,92 .SlateGray 112,128,144
.Indigo 75,0,130 .Snow 255,250,250
.Ivory 255,240,240 .SpringGreen 0,255,127
.Khaki 240,230,140 .SteelBlue 70,130,180
.Lavender 230,230,250 .Tan 210,180,140
.LavenderBlush 255,240,245 .Teal 0,128,128
.LawnGreen 124,252,0 .Thistle 216,191,216
.LemonChiffon 255,250,205 .Tomato 253,99,71
.LightBlue 173,216,230 .Turquoise 64,224,208
.LightCoral 240,128,128 .Violet 238,130,238
.LightCyan 224,255,255 .Wheat 245,222,179
.LightGoldenrodYellow 250,250,210 .White 255,255,255
.LightGreen 144,238,144 .WhiteSmoke 245,245,245
.LightGray 211,211,211 .Yellow 255,255,0
.LightPink 255,182,193 .YellowGreen 154,205,50

free counters

MonoTouch: Building iPhone Apps Using C# and .NET

Posted on Updated on

Novell has released MonoTouch 1.0, what it claims is the industry’s first solution for developing applications for the iPhone and iPod Touch using the Microsoft .NET Framework, including C# and other .NET programming languages. Until now, developers primarily built iPhone


applications using C and Objective-C. With MonoTouch, the creativity of millions of .NET developers worldwide can be unleashed to build a vast array of iPhone applications.

Developed by the Mono Project, an open source initiative sponsored by Novell, MonoTouch simplifies iPhone development by letting developers utilize code and libraries written for the .NET development framework and programming languages such as C#.

MonoTouch is an SDK that contains a suite of compilers, libraries, and tools for integrating with Apple’s iPhone SDK. Microsoft .NET base class libraries are included, along with managed

libraries for taking advantage of native iPhone APIs. Also included is a cross-compiler that can be used for turning .NET executable files and libraries directly into native applications for distribution on the Apple Apps* Store or for deployment to enterprise iPhone users. In addition, Xcode integration enables application developers to test on the device or in Apple’s iPhone Simulator and ship applications to the Apple Apps Store for distribution.

“The vast majority of Windows-centric developers, ISVs and IT organizations have chosen the C# language and .NET for development,” said Miguel de Icaza, Mono project founder and Developer Platform vice president at Novell. “As such we have seen tremendous demand for tools to build .NET-based iPhone applications. We developed MonoTouch in response to this demand, giving both individual developers and businesses a solution that breaks down the barriers to iPhone application development.”

MonoTouch Personal and Enterprise Editions are available now through shop.novell.com. MonoTouch Enterprise Edition is available for $999 per developer for a one-year subscription, which includes maintenance and updates. A five-developer Enterprise license supports five concurrent developers and is available for US $3,999 per year. For individuals only building applications for the Apple Apps Store, MonoTouch Personal Edition is available for $399 per developer for a one-year subscription.