C# 4.0 New Features
What are the new features introduced in c# 4.0?
This is very commonly asked c# interview question. This question is basically asked to check, if you are passionate about catching up with latest technological advancements. The list below shows a few of the new features introduced in c# 4.0. If you are aware of any other new features, please submit those using the from at the end of this post.
1. Optional and Named Parameters
2. COM Interoperability Enhancements
3. Covariance and Contravariance
4. Dynamic Type Introduction
Subscribe to:
Post Comments (Atom)
Hi Venkat,
ReplyDeleteCan we hope an example for each new feature introduced in c#4.0
New featires in c# 4.0 -Lambda expression, LINQ
ReplyDeleteNo, lambda expression and LINQ where introduced in Framework 3.0 before VS 2010.
ReplyDeleteMVC3.0, EF4.1 including in VS2010, no need to install sepratly...
Deletelambda expression and LINQ where introduced in Framework 3.5.
Deleteversion comparability which mean we can execute the the project which is developed in earlier versions of .net framework.
ReplyDeleteDo u work with linq ? If yes how do u use linq?
ReplyDeleteHow we can Say C# is Pure OOPS,If I Declare a Method With Static Keyword then it doesn't need to call with the help of Object.
ReplyDeleteAccessing data is easy if we are familiar with Linq concepts. We can travel through nodes in xml and can modify it as per our need. Instead of using DOM we can use Linq, we can add System.Data.Linq namespace to use it...
ReplyDeleteyes we need example for each of this features..could u please share here pragim..
ReplyDeleteZip extension Method introduced in C# 4.0:
ReplyDeleteWhat is the purpose of ZIP extension method? Explain with example.
The new ZIP extension method introduced in C#4.0 merges two collection sequences by using a predicate function.It is a Combining operator.It combines items from one collection with items from second that are in the same position in the collection.
If Collection A has N items and Collection B has N items (N = 1, 2, 3, 4...), the ZIP extension method will perform the operation as A[N] with B[N].
Let us see an example
Sample input
List firstCollection = new List { 11,12,13,14,15 };
List secondCollection = new List { 6,7,8,9,10 };
Aim:
To perform x + y
Solution using ZIP extension method
var firstCollection = new List { 11,12,13,14,15 };
var secondCollection = new List { 6,7,8,9,10 };
firstCollection
.Zip(secondCollection, (a, b) => a + b)
.ToList()
.ForEach(i => Console.WriteLine(i));
Result
17
19
21
23
25
Explanation:
We are merging the two sequences by using the predicate function ((a, b) => a + b) and using the Foreach extension method performing the display action on each element.
Tuple:
ReplyDeleteC#4.0 has introduce a new feature call Tuple.It is useful when we want to return more than one value from a method or function.
class Program
{
static void Main(string[] args)
{
var returnValue = Calculate();
string format =
"Addition: {0}" + Environment.NewLine +
"Subtraction: {1}" + Environment.NewLine +
"Multiplication: {2}" + Environment.NewLine +
"Division: {3}";
string result = string.Format(format, returnValue.Item1, returnValue.Item2, returnValue.Item3, returnValue.Item4);
Console.WriteLine(result);
Console.ReadKey(true);
}
private static Tuple Calculate()
{
int num1 = 20;
int num2 = 10;
return Tuple.Create(num1+num2,num1-num2,num1 * num2,num1/num2);
}
}
As can be seen that using Tuple we can return multiple values from the function/method in a better and readable way.
@Ganta Vini Don't you think Tuple should be Tuple in your case
ReplyDeleteprivate static Tuple Calculate(){} as you are returning 4 values
why interfaces are introduced??already classes are present...then why???
ReplyDeletewhere can we use enums???give me one real time example??
ReplyDeleteAnywhere you want to limit the type that is used.
Deleteenumerated Day {
Monday = 1,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
}
Used as Day . Wednesday;
Ever thought training in c# mobile using xamarin? The way teach is awesome and there are very little worthy modern tutorials with this technology.
ReplyDeleteMost books are outdated or provide very little information on the entire technology. Videos I have found don't go past hello world and definitely do not explain.
In C# and Visual Basic, covariance and contravariance enable implicit reference conversion for array types, delegate types, and generic type arguments. Covariance preserves assignment compatibility and contravariance reverses it.
ReplyDeleteTask Parallel Library and PLINQ
ReplyDeleteDear sir if you know about WPF then please makes tutorials for us i would be very thanks full to you
ReplyDeleteWhat are the new features introduced in c# 4.0?
ReplyDeleteCan you explain the above said features in detail with examples if possible.
ReplyDelete