background preloader

CSharp

Facebook Twitter

All about C# language and .NET platform

What's New In C# 6.0? 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.

What's New In C# 6.0?

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. With the help of this we can avoid the chances of null errors while accessing property when no value assigned. 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. Expression Bodied Functions Import Static Classes. .net - Create Excel (.XLS and .XLSX) file from C#

Reading and Writing CSV Files in C# Introduction A common requirement is to have applications share data with other programs.

Reading and Writing CSV Files in C#

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. 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. CSV files can easily be read and written by many programs, including Microsoft Excel. For the most part, reading and writing CSV files is trivial. However, there is slightly more work involved.

So this seems like a perfect task for a handy little C# class. Listing 1: CsvFileWriter and CsvFileReader Classes Because the .NET stream classes generally seem to be split into reading and writing, I decided to follow that pattern with my CSV class and split it into CsvFileWriter and CsvFileReader. Using the code Conclusion. 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.

Interfaces and Abstract Classes

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.

Working with Files (Using C# and .NET Framework)

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. 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.

String Format for Double.