The topic of the IDE's controversy has been in the development Department for a long, long-dated and even traceable to Microsoft. NET technology before the release, then the main product is the ActiveX control, with the rapid rise of Borland Delphi, Rad Unstoppable, quickly spawned a lot of classic IDE, Microsoft's most famous is VC and VB, since then. NET technology release, Visual studio into the 20XX era, for VS2002 and VS2003 I have basically not too deep impression, just stay in memory is this goods to high efficiency, must have to install a call ReSharper, otherwise it is stronger than notepad so a little Then Microsoft released VS2005 and VS2008, added the MSBuild engine, optimized smart hints, improved the extended model, basically mature and robust, and then the VS2010 created in WPF technology has been a bloated and gorgeous impression, but the lack of a bright heavy function The last two upgrades and releases are VS2012 and VS2013, and the few major points that are placed on the headlines are not the performance of the web and the cloud.
Microsoft said in a few days that the official release date for Visual Studio 2015 was July 20, which was quickly discussed in the development department, which was divided into three groups:
- Technology flow--I go, this IDE comes and goes is not so many functions, a variety of super "notepad" can be done, why earn broken head to upgrade, as long as the technology has not changed, seemingly desktop or WinForm-based, WPF dead-end; the web is a big deal, but it's a running environment. , in addition to compiling or MSBuild, it seems that the whole point is small.
- Chasing new stream--Haha, Microsoft has a new version, fast download to try it, this time there must be a lot of killer features, such as c#6.0, as well as the new Roslyn compiler platform, in addition to the ASP. NET 5.0 is very interesting, and finally take off the reliance of system.web, the whole line instead of Owin.
- Calm flow-Let them this batch of mice first drip, it is really cool to say, anyway, now the task has not to have this.
Ultimately, the new stream sounds bigger, because everyone is looking forward to the new version of C #, although the Microsoft C # language group's PM Mads Torgersen said, "C # 6.0 is primarily about enhancing and improving efficiency," but for the control development team it is still quite looking forward, Because the readability and efficiency of the code is a very critical part of us.
Here, let's get back together. Briefly review the important features of c#6.0:
- An nameof expression. Once upon a time, we have been hardcode various parameter anomalies, such as:
void Throwargumentnullexception (String firstversionargumentname)
{
Threw new ArgumentNullException ("Firstversionargumentname", "Can not is null");
}
Very sad urging is the second edition maybe PM said: "This parameter name is not appropriate, we change it", thanks to the IDE's refactoring function, this is easy, directly F2 renamed and then enter, check in code; After a few days, the test came to the door, saying that your parameter name is changed, but the exception information has not changed. Well, the original HardCode character set, this is not changed with the refactoring function!
Take a look at what the new nameof expression brings me, the same functionality as the code:
void Throwargumentnullexception (String firstversionargumentname)
{
Threw new ArgumentNullException (nameof (firstversionargumentname), "Can Not is null");
}
When you go back to the IDE and press F2 again to trigger a rename, you'll find that the exception information can also be changed together.
- Null-valued operator (null-conditional operators), another heavyweight code boost, directly on the sample code:
public static string Tuncate (this string value, int length)
{
if (!string. IsNullOrEmpty (value))
{
return value. Substring (0, Math.min (value. length, length));
}
return value;
}
This is only a small folding, in the development process we have countless such methods, countless repetitions of the empty judgment, but this code readability and business processing without any promotion, but increased the complexity of the code, making it more difficult for us to understand the original design. Clearly, c#6.0 uses null-conditional operators to advance a big step forward:
public static string Tuncate (this string value, int length)
{
return value?. Substring (0, Math.min (value. length, length));
}
is not more concise and clear, but also to highlight the core business logic!
- String embedding value (string interpolation), finally can get rid of long string. The Format function, the following code can be easily rewritten:
var fullName = string. Format ("FirstName is {0}, LastName is {1}", customer. FirstName, customer. LastName);
After using the new feature code:
var fullName = "FirstName is \{customer. FirstName}, LastName is \{customer. LastName} ";
- Lambda expression functions and get-only properties. For those functions that have only one or two sentences, you can save some nonsense, and this new feature can be very labor-saving:
public override string ToString () = "\{firstname} \{lastname}";
public override int GetHashcode () = (Firstname.gethashcode () ^8) & (Lastname.gethashcode ());
Public DateTime TimeStamp {get;} = Datetime.utcnow;
- public string FirstName {get; set;} = "John";
public string LastName {get; set;} = "Lennon";
private Dictionary<int , string> _dicts = new Dictionary<int, string> {[3] = "Third", [8] = "Eight"};
public string FullName {get;} &NBSP;
pubic MyClass ()
}
- exception filter (Exception filter), recall the error handling, in order to prompt a different error , we have to define multiple custom exceptions, with the exception filter, we can solve by adding a simple extra property to the exception: &NBSP;
try {...} &NBSP;
{...} &NBSP;&NBSP;
- using GRAPECITY.DEMO.LONGLONGNAMESTATICCLASS;&NBSP;
void AnotherMethod () < BR style= "margin:0px; padding:0px; " >{&NBSP;
UtilA (...)//No Longlongnamestaticclass.utila (...) &NBSP;
- await enhancement, finally can put the await in catch and finally block, A typical use case is a simple and neat process such as an IO resource operation closed: &NBSP;
TRY&NBSP;
...
catch (Resourceexception ex )
{
await Resource.logasync (res, ex); Write a log, do not block
finally &NBSP;
{
res?. Closeasync (); Combining null-valued operator is more concise and clear
}
The c#6.0 feature is here, and in the second we'll look at the VS2015 code editing and debugging related content to see how vs 2015 improves efficiency and quality. Keep your eye on it!
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Visual Studio 2015 Express (1)--c#6.0 How to use the new features