Monday, September 24, 2007
Thursday, September 13, 2007
Var Keyword in C# - .Net 3.5 Orcas Feature
In .Net 3.5 Orcas consist of a keyword called var. This keyword can be used to reference any type in c#. For example,
The compiler will infer the type of the "name", "age" and "single" variables based on the type of their initial assignment value
var name = "raja";
var age = 26;
var single = true;
var age = 26;
var single = true;
The compiler will infer the type of the "name", "age" and "single" variables based on the type of their initial assignment value
string name = "raja";
int age = 26;
bool single = true;
int age = 26;
bool single = true;
What are Extension Methods?
Extension methods allow developers to add new methods to the public contract of an existing CLR type, without having to sub-class it or recompile the original type. Extension Methods help blend the flexibility of "duck typing" support popular within dynamic languages today with the performance and compile-time validation of strongly-typed languages.
Extension Methods enable a variety of useful scenarios, and help make possible the really powerful LINQ query framework that is being introduced with .NET as part of the "Orcas" release.
Simple Email validation class in .Net 3.5 - Orcas Feature
There is a class named EmailValidator in .Net 3.5 to validate email address. This class contain a static method called "IsValid" to validate email string. Sample code given below.
There is another way to validate email string.
string email = "raja@test.com";
if ( EmailValidator.IsValid(email) ) {
}
if ( EmailValidator.IsValid(email) ) {
}
There is another way to validate email string.
string email = "raja@test.com";
if ( email.IsValidEmailAddress() ) {
}
if ( email.IsValidEmailAddress() ) {
}
Subscribe to:
Posts (Atom)