background preloader

CSharp

Facebook Twitter

All about C# language and .NET platform

What's New In C# 6.0? | Canarys. Microsoft has released the preview version of Visual Studio 2015 and .NET 4.6 for developers to try and provide feedback on usage or issues. .NET 4.6 preview comes with C# 6.0 which includes the new additional features expected by developers to improve the coding productivity. In this article I am going to describe the new features introduced in C# 6.0. If you haven’t download the Visual Studio 2015 please get it from below download button. Property Initialization with default value In C# 6.0 we can initialize the default value to property right from the place we create it.

Old Style: public int Id { get; set; } public string FirstName { get; set; } New Style: public int Id { get; set; } = 1001; public string FirstName { get; set; } = "Srinivas"; String Interpolation The most common thing we use in our daily coding is String concatenation. This usage is very much simplified in C# 6.0 by adding expression which replaces the numbered placeholders. Expression Bodied Functions Import Static Classes try. .net - Create Excel (.XLS and .XLSX) file from C# Reading and Writing CSV Files in C# Download Test Project Introduction A common requirement is to have applications share data with other programs. Although there are interfaces available to work with, for example, Microsoft Excel data files, this approach is generally complex, involves a fair amount of overhead, and requires that support libraries accompany your application.

Note that the code below is a complete rewrite of the code presented when this article was first published. I decided to make the code more robust and add a number of new features that include support for multi-line values and the ability to change the characters used for delimiters and quotes. I also added several options to control how the CSV reader class handles empty lines. Comma-Separated Values (CSV) Files A much simpler way to have your application share data is by reading and writing Comma-Separated Values (CSV) files. For the most part, reading and writing CSV files is trivial. However, there is slightly more work involved. Using the Code. Interfaces and Abstract Classes.

Download sample - 13.3 KB Introduction I often see people asking what's the difference between an interface and an abstract class and most answers only focus on the different traits, not on how to use them. That is, most answers will tell things like: An abstract class can have an implementation while an interface can't; In .NET we don't have multiple inheritance, so we can't use multiple abstract base classes, but we can implement multiple interfaces; An interface is a contract, an abstract class is more than that (this one actually says nothing useful to me, but it is a common answer). Well, there are many other answers that go in the same direction. When should we use an interface and when should we use an abstract class?

Short answer: If we want to create a method that receives an object to call one or more of its methods, expecting those methods to have different implementations according to the received object, we should ask for an interface. Input arguments - Always use interfaces. Working with Files (Using C# and .NET Framework) Introduction This article tries to explain the basics about the files and the directories in the system.

How can a developer develop a software that would interact with the File system, create new files, modify or edit the currently existing files and/or move them to new locations in the file system or delete them at all. This article has the code explained for the total beginners for the .NET Framework and C# and the File or Directory class. It would help them understand what these classes are, and what they can do with them. Background Working with Files (specially images) is considered to be a hard work, and a tough time is given to the developer in developing the projects. But .NET Framework has really cool API, that helps you to do all these functions very fastly.

You don't even have to go to the next line while writing the code to create a new file if you're using .NET Framework. System.IO In the .NET Framework there are classes defined for each process and functionality. Directories. String Format for Double.