This article explains the first look of Visual Studio 15 Preview. It will cover some important and new features and enhancements done in Visual Studio 15 such as performance, supported features of C# 7.0, Conditional Compilation Options, IDE improvements, etc.
As we know Microsoft has announced it new version of Visual studio; i.e., Visual Studio 15. Please do not be confused with Visual Studio 2015 (Visual Studio 14). Many developers are getting confused with Visual 2015 so I am going to clarify the difference so that you can understand it easily. Visual Studio 2015 is a product name having the version number Visual Studio 14 and here I am talking about Visual Studio 15; that product name may be announced as Visual Studio 2016 or Visual Studio 2017. To understand it more clearly have a look at the below screenshot.
- Up to 30 percent faster than Visual Studio 2015
As per Microsoft, Visual Studio ‘15’ starts at 30 percent faster than Visual Studio 2015, but it varies from PC to PC and when I tested it at my end then the result was very different. On my laptop, Visual Studio ‘15’ took only 3 seconds to start whereas Visual Studio 15 took 10 seconds to start. I installed Visual Studio 2015 6-7 month ago and I was unhappy witthe start time of Visual Studio 2015 and I think Microsoft has taken this issue seriously andare doing start time improvements in an upcoming version.
- Using Local Functions or Nested Functions (Feature of C# 7)in Visual Studio Preview
Using local functions inside a function is called local function. Even though C# 7 has not been announced officially, some features are being added with C# which developer communities are saying is C# 7. To understand how local function works just have a look atthe below code and see how you are going to write and call Add() and Multiply() methods.
- usingstatic System.Console;
- namespace UseLocalFunctions
- {
- classProgram
- {
- staticvoid Main(string[] args)
- {
-
- void Add(int x, int y)
- {
- WriteLine($ "Sum of {x} and {y} is : {x + y}");
- }
-
- void Multiply(int x, int y)
- {
- WriteLine($ "Multiply of {x} and {y} is : {x * y}");
- Add(30, 10);
- }
- Add(20, 50);
- Multiply(20, 50);
- }
- }
- }
Output
If you are not aware about C# 6.0 features and you are wondering how WriteLine() method is used without Console and what is $ “” then please visit the below links for details,
- Using Static Classes as Directive in C# 6
- C# 6.0 String Interpolation
But when I tried to run the same code inside Visual Studio 2015 SP1 then I got a lot exceptions and warning. Please have a look at the below screenshot which displays the build error in Visual Studio 2015.
- Using Binary Literal
Inthe new version of C# we can use binary literals in the same way as hexadecimal literals are used.
C# supports Hexadecimal literas and we use 0x or 0X and now C# will support binary literals too and we will use 0b and 0B for binary literals.
- usingstatic System.Console;
- namespace VisualStudio15FirstLook
- {
- classProgram
- {
- staticvoid Main(string[] args)
- {#region Using Binary Literal
- int x = 0b1010000;
- int SeventyFive = 0B1001011;
- WriteLine($ " {x} \n {SeventyFive}");#endregion
-
-
- # region Using Hexadecimal Literal
- int a = 0x50;
- int b = 0X4B;
- WriteLine($ " {a} \n {b}");#endregion
-
- }
- }
- }
As stated earlier hexadecimal literalis already supported in C# and if you run the same code inside Visual Studio 2015 then you will get error for binary literal but hexadecimal literals are compiled successfully. Refer to the below screenshot for the build error being displayed for the same code with Visual Studio 2015.
- Using Digit Separators
Digit separator is also a new feature in C# which is supported with Visual Studio ‘15’ preview. We can use one or more than one Underscore( _ ) character for digit separators, so the code snippet would look something like:
- #region Using Digit Separators
- int binaryData = 0B0010_0111_0001_0000;
- int hexaDecimalData = 0X2B-67;
- int decimalData = 104_567_789;
- int myCustomData = 1___________2__________3___4____5_____6;
- double realdata = 1_000.111_1e-1_000;
- WriteLine($" binaryData :{binaryData} \n hexaDecimalData: {hexaDecimalData} \n decimalData: {decimalData} \n myCustomData: {myCustomData} \n realdata: {realdata}");
- #endregion
This feature will work only with Visual Studio ‘15’ preview and not with VS 2015.
- Pattern matching
-
- var myData = "Custom Data";
- var myData2 = myData isstring ? "aaaaa":"bbbbbb";
- var myData3 = myData isstring a ? a : "Not a String";
-
- WriteLine(myData2);
- WriteLine(myData3);
-
-
-
- var x = 10;
- var y = 0b1001;
- var z = y isint ? $"{y * x}" : "Invalid data";
-
- WriteLine(z);
Apart from this we can use a lot of other types of pattern matchings like Type Pattern, Constant Pattern, Var Pattern, Recursive Pattern, Property Pattern& Property Sub-pattern, Switch Statement, Match Expression, Case expression, Throw expression, Destructuring assignment,Testing Nullable, Arithmetic simplification, Tuple decomposition, Complex Pattern,Wildcard Pattern etc.
- Custom Code Style Enforcement (C# Code Style Preferences)
The Custom Code Style Enforcement option provides us the feature to add some preferences. It has three sections of preferences,
a. ‘this.’ preferences,
b. predefined type preferences
c. var preferences
You can open this window by navigating to Tools > Options > Text Editors > C# > Code Style,
- Execute in Interactive (Execute your Code Snippet Inside C# Interactive Window)
Now you can execute a code snippet very easily using C# interactive window to do this you just need to select the code snippet and press “Ctrl+E,Ctrl+E”
or you can use context menu for it. Select the code snippet and right click on it.
- New compiler flags: two new compiler flags have been added deterministic&publicSign.
- ref returns and Ref Locals.
- Add Conditions to Exception Settings
in Visual Studio ‘15’ preview we can add conditions for break and thrown exceptions and we can set how to handle this if it is coming from a particular module.
Suppose FileNotFound exception occurs from PDFConversion.dll then we can se whether that application should break or not etc.
- Open Folder (New Feature in Visual Studio 15 Preview)
Apart from this in Visual Studio ‘15’ preview you can open and edit any code from any folder.
- Edit & Continue for XAML apps (WPF & Universal Windows App):
In Visual Studio ‘15’ preview we can edit XAML while application is running and new code change will be reflected immediately i.e. we do not need to recompile the application.
Here I have focused only on Visual Studio IDE and C# new features but this is not a complete list and Microsoft has added lot of new features for Apache Cordova, Visual C++, Team Explorer, SSDT, Nuget, Application Insights& JavaScript.
Read more articles on Visual Studio:
180