How do you see .NET / C # 5.0?
Most recently, we received the release of .NET / C # 4.0. We talked a lot (and will talk more) about the new features and innovations of the new platform and language. But you can already draw some conclusions and think about what we want to see in the new version of .NET / C # 5.0?
In 4.0, a new Tuple data type has appeared that can be used this way:
It was great to use Tuple in abbreviated form, for example:
or
It would be nice to pass enums to generic methods, for example:
You can also make enums classes (as it is now in Java).
Why not add operator support to generic methods?
A simple way to check if a variable is in a specific set or range of values:
He himself sometimes wondered why, in addition to extension methods, also extension properties. Those. instead
writing is easy
Let's extend the switch to support expressions, conditions, etc.:
By the way, VB.NET supports this syntax.
Basically, a good idea:
It is often necessary to use the property of some property of an object, which leads to a large series of checks. Why not do it like this:
Or for example, instead
write
Well, something like this:
Although something similar can be done now - handle the necessary exceptions in order of importance, and all the rest - using a general Exception.
Multiple inheritance, virtual extension methods, the ability to process files with long names ... You can participate in the discussion of this issue on stackoverflow .
What would you like to see in .NET / C # 5.0 and which of the above ideas would you like to use?
Tuple Packaging and Unpackaging
In 4.0, a new Tuple data type has appeared that can be used this way:
var data = new Tuple(“John Doe”, 42);
It was great to use Tuple in abbreviated form, for example:
public string, int, double ReturnMyTuple ()
{
return "Hello World!", 42, 4.2;
}
or
public tupleReturnMyTuple ()
{
return "Hello World!", 42, 4.2;
}
// elsewhere: item1 is a string, item2 is an int, item3 is a double.
var item1, item2, item3 = ReturnMyTuple ();
Enums, Generics
It would be nice to pass enums to generic methods, for example:
public void DoSomething(T enum) where T: System.Enum {...}
You can also make enums classes (as it is now in Java).
Why not add operator support to generic methods?
T add(T a, T b)
{
return a + b;
}
In Keyword and Ranges
A simple way to check if a variable is in a specific set or range of values:
if (x in (1, 2, 3)) {}
if (x in [5..10]) {}
if (x in [1, 2, 4..8, 10]) {}
Extension Properties
He himself sometimes wondered why, in addition to extension methods, also extension properties. Those. instead
var value = someObject.Value ();
writing is easy
var value = someObject.Value;
Smart switch
Let's extend the switch to support expressions, conditions, etc.:
switch (anInt)
{
case 1, 2:
Console.WriteLine ("1 or 2");
break;
case 3..9:
Console.WriteLine ("3 to 9");
break;
case> = 10:
Console.WriteLine ("10 or higher");
break;
default:
...
}
switch (aString)
{
case "one", "two":
Console.WriteLine ("1 or 2");
break;
case "three":
Console.WriteLine ("3");
break;
default:
switch (aString)
{
case .IsNullOrEmpty ():
...
case .Length> 100:
...
case .Contains ("foo"):
...
}
By the way, VB.NET supports this syntax.
Automatic flags at Enums
Basically, a good idea:
[Flags]
public enum MyFlags
{
Value1, // 1
Value2, // 2
ValueCombining1And2 = Value1 | Value2, // 3
Value3, // 4
Value4, // 8
ValueCombining3And4 = Value3 | Value4 // 12
}
More advanced null checking
It is often necessary to use the property of some property of an object, which leads to a large series of checks. Why not do it like this:
MyClass value = null;
int something = value.xy ??? 0; // can I use a triple character here?
// something is now 0
Or for example, instead
var obj = Foo ();
Bar value = null;
if (obj.Bar! = null && obj.Bar.Something! = null)
{
value = obj.Bar.Something.DoSomething ();
}
write
var obj = Foo ();
var value = obj? .Bar? .Something? .DoSomething ();
Exception grouping
Well, something like this:
try
{
}
catch (ArgumentOutOfRangeException)
catch (ArgumentNullException)
{
// Catch a ArgumentOutOfRangeException or a ArgumentNullException
}
Although something similar can be done now - handle the necessary exceptions in order of importance, and all the rest - using a general Exception.
Yet...
Multiple inheritance, virtual extension methods, the ability to process files with long names ... You can participate in the discussion of this issue on stackoverflow .
What would you like to see in .NET / C # 5.0 and which of the above ideas would you like to use?