Skip to main content

C# Version 7.0

There have been a number of changes, improvements and features made to C# 7.0 release of the next version of Visual Studio. In this article, I’m going to introduce the biggest features and changes, which have been announced. Thus, we all are quite familiar with the previous versions of C#, which are very useful language features to remove an unexceptional code and clean up our code.

Nowadays, programmers don’t want to suffer with error prone code or writing extra code --  they want an environment of convenient coding where they can get some simple and delightful code . We can see some features in C#,
  • Portability
  • Advanced runtime (garbage collection)
  • Easy to adopt
  • Native access
  • Fast execution
  • Reliability (type safety)
  • Powerful features (reflection and dependency injection)
  • Cutting edge (asynchronous programming)
C# 7.0 features come with the concise and shorter format for the wide use. C# 7.0 features are highly portable in a wide range of environments over the spectrum of mobile, Server computing, embedded and desktop. In this announcement, the features are highly expressive and it's easy to maintain the code. Here are a few new features in this announcement-
  • Multi-value Returns
  • Pattern Matching: Enhanced Switch Blocks
  • Pattern Matching: Decomposition
  • Tuple as a Mutable type
  • Partial Class Enhancements
  • Local Functions
  • Binary Literals
  • Ref Returns
There is No need to declare variables - In C# 7.0, there is no need to declare the variables, outside of the method from which, you are going to get it. It will be required only to add out before the variable and use it later on. Thus, it can be declared directly as the arguments such as a parameter.

Wildcards for ignoring Out parameters – This would be a great thing, as the idea of an out parameter, using wildcard* is of ignoring out parameters.


Pattern matching mechanism - This is a whole new mechanism, which will be introduced in C# 7, which for now will be used for checking  the objects in three types,
  • Constant patterns of the form c (where c is a constant expression in C#), which tests that the input is equal to c.
  • Type patterns of the form T x (where T is a type and x is an identifier), which tests that the input has type T and if so, it extracts the value of the input into a fresh variable x of type T.
  • Var patterns of the form var x (where x is an identifier), which always matches and simply puts the value of the input into a fresh variable x with the same type as the input.

Switch Case extended to use different object types - Switch case is no longer only using the primitive types, it is now also able to use custom types, as the example, given below shows-

Extended Tuples - Tuples are now extended to be more friendly. Now, you can also declare the tuple functions and can be returned in more friendly way. C# offered a tuple as a value type.

To create a tuple, you can use this syntax, given below-
  1. var sum = (5, 20);  
The main things about the tuples are-
  • You can specify the element names in tuple literals.
  • Their elements are public and mutable fields.
  • Two tuples can have the same hash code.

Deconstruction of tuples - Deconstructing declaration is syntax for splitting a tuple (or other value) into its parts and assigning those parts individually to the fresh variables.

In this, you can use the variables in different manners such as-
  • Var inside parenthesis
  • Var outside of the parenthesis
  • Deconstructing assignment ((first, middle, last) = StudentName (studId1) ;)
You can define function inside method's body - Now, if the function is only used in one method, you can define in in the method's body.


Local functions are the functions, which we define inside another function. You can't create a delegate, which points to the local function.

Literal Improvements - C# 7.0 allows occurrence of a digit separator inside number literals, which means it is allowed for better readability along with the binary literals.


You can specify bit patterns as well binary literals.

Extended ref, you can return by ref - Until now, we were able to pass as ref one parameter. Now, we can also return them by the references and also store them as the reference. Thus, you can't return a reference to a local variable.
  1. var a = ref FourthElement(myArray)  
  2. a = 10; //MyArray[4] now equals 10 

More expression bodied members - There are new things here as well. Now, you can add a destructor to the expression bodies. Expression bodied members are available for both the methods and properties.


Throw exception inside expression - Now you can throw exception inside expression or middle of expression (in certain place). 


other new feature will be added soon .... thanks for reading this artical

Comments

Popular posts from this blog

Claims Class For security in .NET4.5 with C#

What is Claim ? A claim in the world of authentication and authorization can be defined as a statement about an entity, typically a user. A claim can be very fine grained: Ram is an admin Ram’s email address is Ram@yahoo.com Ram lives in Mumbai Tom’s allowed to view sales figures between 2009 and 2012 Tom’s allowed to wipe out the universe Claims originate from a trusted entity other than the one that is being described. This means that it is not enough that Tom says that he is an administrator. If your company’s intranet runs on Windows then Tom will most likely figure in Active Directory/Email server/Sales authorisation system and it will be these systems that will hold these claims about Tom.  The idea is that if a trusted entity such as AD tells us things about Tom then we believe them a lot more than if Tom himself comes with the same claims . This external trusted entity is called an  Issuer . The KEY in the key-value pairs is called a  Typ...

Paytm integration

How to integrate Paytm to asp.net site   You will need to create an Checksum on your server. Kindly refer the dll file for the attachment.  Usage of CheckSum API: ·         Add provided “paytm.dll” as a “Reference” in your project. ·         Import namespace “paytm” in your Class with statement “using paytm”. ·         Now Generate CheckSum API as well as Verify CheckSum API are available as follows: o   String CheckSum.generateCheckSum(String masterKey, Dictionary<String, String> parameters) o   Boolean CheckSum.verifyCheckSum(String masterKey, Dictionary<String, String> parameters, StringcheckSum) ·         For Generating CheckSum, use following snippet code: String masterKey = “merchantKey” ; Dictionary<String, String> parameters = new Dictionary<string, string>(); p...

Javascript ECMAScript6 New Feature

Extended Parameter Handling Another nice set of features introduced in ES6 is the extended parameter handling. These provide a very nice set of idioms that bring us very close to languages like C# or Java. Default parameter values and optional parameters Default parameters allow your functions to have optional arguments without needing to check arguments.length or check for undefined. Let’s take a look at what that might look like: let greet = (msg = 'hello', name = 'world') => {   console.log(msg,name); } greet(); greet('hey'); Looking at the preceding code, you can see that we are using the new fat arrow (=>) syntax as well as the new let keyword. Neither of those are necessary for this example, but I added it to give you more exposure to the new syntax. Running the preceding code produces the following result: hello world hey world  Rest parameter Handling a function with a variable number of arguments is always t...