RSS

C# feature & Update version by version


C# List features

C# 1.0

Microsoft released the first version of C# with Visual Studio 2002. Use of Managed Code was introduced with this version. C# 1.0 was the first language that developer adopted to build .NET applications.

C# 2.0

Microsoft released the second version of C# language with Visual Studio 2005. C# 2.0 has introduced few new features in this edition which helped the developers to code their applications in more generic way. Here are the new features that were introduced with C# 2.0:

  1. Generics
  2. Anonymous Methods
  3. Nullable Type
  4. Partial Class
  5. Covariance and Contravariance

C# 3.0

Visual Studio 2008 came with C# version 3.0 and it has a bunch of new features. It was the life-changing the language for Microsoft platform developers to build their applications. Till now, many developers are still using this version to build their apps. The new features that came with C# 3.0 were:

  1. Lambda Expression
  2. Extension Methods
  3. Expression Trees
  4. Anonymous Types
  5. LINQ
  6. Implicit Type (var)

C# 4.0

Though C# 4.0 was released with Visual Studio 2010 with .NET Framework 4, very few developers use its new features till date. Here is a list of new features of C# that came with this version:

  1. Late Binding
  2. Named Arguments
  3. Optional Parameters
  4. More COM Support

C# 5.0

Visual Studio 2012 came up with C# 5.0 and it was made available to the audience in the year 2012. In C# version 5.0, there are two key features:

  1. Async Programming
  2. Caller Information

C# 6.0

The C# 6.0 release contained many features that improve productivity for developers.  Some of the features in this release were:

  1. Read-only Auto-properties
  2. String Interpolation
  3. await in catch and finally blocks
  4. index initializers
  5. Null- conditional operators

C# 7.0

C# 7.0 is the current version (at the time of writing this article) which adds a number of new features to the C# language:

  1. Pattern Matching
  2. out variables
  3. throw Expressions
  4. Tuples
  5. ref locals & returns and few more…

C# 7.1

C# 7.1 is the new version (at the time of updating this article) which again adds a couple of new features to the C# language:

  1. Asynchronous Main – Main could be void or int and contain arguments as a string array.
  2. Default Literal – Visual Basic and C# have similar features, but there are certain differences in the languages, i.e. C# has null, while VB.NET has Nothing.

That’s all as per this post is concerned. We will update this list as soon as new version is out in the market.

C# version history in tabular format for quick view:

Version Date .NET Framework Visual Studio
C# 1.0 Jan-02 .NET Framework 1.0 Visual Studio .NET 2002
C# 1.1/1.2 Apr-03 .NET Framework 1.1 Visual Studio .NET 2003
C# 2.0 Nov-05 .NET Framework 2.0 Visual Studio .NET 2005
C# 3.0 Nov-07 .NET Framework 2.0 (Except LINQ),.NET Framework 3.0 (Except LINQ),

.NET Framework 3.5

Visual Studio .NET 2008,Visual Studio .NET 2010
C# 4.0 Apr-10 .NET Framework 4.0 Visual Studio .NET 2010
C# 5.0 Aug-12 .NET Framework 4.5 Visual Studio .NET 2012/2013
C# 6.0 Jul-15 .NET Framework 4.6 Visual Studio .NET 2015
C# 7.0 Mar-17 .NET Framework 4.6.2 Visual Studio .NET 2017

Expected New Features In C# 8.0

Recently in channel 9, Mads Torgersen demonstrated the first four features of C# 8. Below is the brief description of those new features in C# 8.0. This is going to be the next major release after C# 7.0

Expected New Features In C# 8.0

C# 8.0 Previewed: below are the 4 features which Mads discussed in his recent talk on channel 9.

1. Nullable Reference Types

 

With C# 8.0, references type would not be nullable by default. Assigning null to a non-nullable reference type will be a compiler warning, similarly reading from a nullable type would also be a compiler warning unless the variable in question was explicitly checked for null ahead of time.

2. Async Streams

Async streams are the asynchronous equivalent of IEnumerable. The syntax for the same is:

foreach await (string in asyncStream)

Read more http://dotnetcrunch.com/expected-new-features-in-csharp8/

3. Default Interface Implementations

A default interfaces programming capability, so interfaces can evolve via virtual extension methods. An API author could add methods to an interface in future versions without breaking source or binary compatibility. This feature already is available in programming languages such as Java.

For a detailed explanation refer –

Interface Method Implementation C# 8.0.

The most cited use case for this feature is the ability to add a Count property to IEnumerable<T>. The idea is that instead of using the Enumerable.Count extension method, developers can get Count for free and optionally override it if they can provide a more efficient alternative.

interface IEnumerable<T>
{
    int Count()
    {
        int count = 0;
        foreach (var in this)
            count++;
        return count;
    }
}
interface IList<T> ...
{
    int Count { get; }
    override int IEnumerable<T>.Count() => this.Count;
}

Read more http://dotnetcrunch.com/expected-new-features-in-csharp8/

 Extension Everything

Extension properties were the long-time pending feature. Under the new design, there is a new top-level construct called an extension. For example, if you want to create extension methods and properties for a Student class you would write:

extension StudentExt extends Student {
    //methods and properties go here
}

In this video, Mads Torgersen talks about some of the planned features of C# 8.0.

https://channel9.msdn.com/Blogs/Seth-Juarez/A-Preview-of-C-8-with-Mads-Torgersen/player

For more information, you can refer C# Language Design Repo and the proposal section.

Advertisements
 
Leave a comment

Posted by on November 2, 2017 in C# Concept

 

Tags:

Add New column in existing MySQL table Specific Row


To add a column LastName to the Student table with a datatype of VARCHAR(60), use the following SQL statement:

ALTER TABLE Student ADD LastName VARCHAR(60);

This first statement will add the LastName column to the end of the table.If you insert the new column after a specific column, such as FirstName, then use this statement:

ALTER TABLE Student ADD LastName VARCHAR(60) AFTER FirstName;

If you want to Add new column to first Column, Then use this statement:

 

ALTER TABLE Student ADD LastName VARCHAR(60) FIRST;

If you want to Add new column with Default Value, Then use this statement:

ALTER TABLE Student ADD LastName VARCHAR(60) Default 0;

 
Leave a comment

Posted by on November 19, 2015 in My SQL

 

Tags: ,

devexpress multiple gridview export to excel in Single File winforms


After two much searching of this solution to export multiple gridview data to single Excel file with separate Sheet of Excel.

Then i find this solution which resolve my problem. this is 100% tested and use in my project . after that i share with you in both language c# and vb.net.

 

 Solution :: Vb.Net

Imports DevExpress.XtraPrinting
Imports DevExpress.XtraPrintingLinks

 

Public Sub MultiFileExportToExcel()

Using saveDialog = New SaveFileDialog()
saveDialog.Filter = “Excel (.xlsx)|*.xlsx”
If saveDialog.ShowDialog() = DialogResult.OK Then
Dim printingSystem = New PrintingSystemBase()
Dim compositeLink = New CompositeLinkBase()
compositeLink.PrintingSystemBase = printingSystem

Dim link1 = New PrintableComponentLinkBase()
link1.Component = grid1
Dim link2 = New PrintableComponentLinkBase()
link2.Component = grid2

compositeLink.Links.Add(link1)
compositeLink.Links.Add(link2)

Dim options = New XlsxExportOptions()
options.ExportMode = XlsxExportMode.SingleFilePageByPage

compositeLink.CreatePageForEachLink()
compositeLink.ExportToXlsx(saveDialog.FileName, options)
End If
End Using
End Sub

 

Solution ::  C#

using DevExpress.XtraPrinting
using DevExpress.XtraPrintingLinks

public void exportToExcel()
{
using (var saveDialog = new SaveFileDialog())
{
saveDialog.Filter = “Excel (.xlsx)|*.xlsx”;
if (saveDialog.ShowDialog() == DialogResult.OK)
{
var printingSystem = new PrintingSystemBase();
var compositeLink = new CompositeLinkBase();
compositeLink.PrintingSystemBase = printingSystem;

var link1 = new PrintableComponentLinkBase();
link1.Component = grid1;
var link2 = new PrintableComponentLinkBase();
link2.Component = grid2;

compositeLink.Links.Add(link1);
compositeLink.Links.Add(link2);

var options = new XlsxExportOptions();
options.ExportMode = XlsxExportMode.SingleFilePageByPage;

compositeLink.CreatePageForEachLink();
compositeLink.ExportToXlsx(saveDialog.FileName, options);
}
}
}

 

Reference url;

https://www.devexpress.com/Support/Center/Question/Details/A2730

 
Leave a comment

Posted by on April 22, 2015 in Vb.Net, WinForm

 

Tags: ,

Deleting older files after a specified number of days using VB.NET


If You want to Temp or your specific Export file History maintain folder to delete file after some days then this function resolve your problem.

Calling Way:

First Way : 

Dim DeleteInfo As Long()

DeleteInfo = DeleteFilesXDaysOld("c:\temp\", "*.*", 60)

Console.Writeline(DeleteInfo(0) & " file(s) deleted.")
Console.Writeline("Freeing " & DeleteInfo(1) & " bytes.")


Second Way:

Imports System.IO

 Dim DeleteInfo As Long()
 If My.Computer.FileSystem.DirectoryExists(Path.GetTempPath & "\Export\Invoice") = True Then
 DeleteInfo = DeleteFilesXDaysOld(Path.GetTempPath & "\Export\Invoice", "*.*", 2)
 End If

Check Directory Exist or Not in Vb.Net else create

Dim GLFilePath as string = Path.GetTempPath & "\Export\Invoice"

 If My.Computer.FileSystem.DirectoryExists(Path.GetTempPath & "\Export\Invoice") = False Then
 My.Computer.FileSystem.CreateDirectory(Path.GetTempPath & "\Export\Invoice")
 End If

Function Delete Files:

Private Function DeleteFilesXDaysOld( _ ByVal Path As String, _ Optional ByVal Pattern As String = "*.*", _ Optional ByVal Days As Integer = 365) As Long() ' ReturnValues is an array which holds 2 values ' The first being the count of files deleted ' The second being the amount of space freed Dim ReturnValues = New Long() {0,0} Dim File As String Dim FileInfo As System.IO.FileInfo Dim Files() As String = _ System.IO.Directory.GetFiles(Path, Pattern) Try For Each File In Files FileInfo = New System.IO.FileInfo(File) If FileInfo.LastWriteTime < _ Today.AddDays(0 - Days) Then ReturnValues(0) += 1 ReturnValues(1) += FileInfo.Length() FileInfo.Delete() End If Next Return ReturnValues Catch exn As Exception MsgBox(exn.ToString, _ MsgBoxStyle.Critical Or _ MsgBoxStyle.OkOnly Or _ MsgBoxStyle.SystemModal, _ "Error") Return ReturnValues End Try End Function

 
1 Comment

Posted by on February 15, 2015 in Vb.Net

 

Tags: , , , , ,

group by sequence number MySQL


Before you use below sample code i prefer you use this URL code which better for you.

http://blog.sqlauthority.com/2014/03/09/mysql-reset-row-number-for-each-group-partition-by-row-number/

 

SAMPLE DataTable

CREATE TABLE CountryCity
 (
 city VARCHAR(100),
 country VARCHAR(100),
 population int
 );

INSERT INTO CountryCity VALUES ('Lahore', 'Pakistan',8175133); 
 INSERT INTO CountryCity VALUES ('Multan', 'Pakistan',3792621); 
 INSERT INTO CountryCity VALUES ('Liquat Pur', 'Pakistan',2695598); 
 
 INSERT INTO CountryCity VALUES ('Kalkata', 'India',2181000);
 INSERT INTO CountryCity VALUES ('Dehli', 'India',808000);
 INSERT INTO CountryCity VALUES ('Goya', 'India',422000);
 
 INSERT INTO CountryCity VALUES ('Riyadh', 'KSA',7825300);
 INSERT INTO CountryCity VALUES ('Madina', 'KSA',1016800);
 INSERT INTO CountryCity VALUES ('Makkah', 'KSA',770800);

MySQL Query to Get Top 2

To get the 2 largest Country cities for each country, you can use the following query in MySQL:
SELECT city, country, population
FROM
(SELECT city, country, population,
@country_rank := IF(@current_country = country, @country_rank + 1, 1) AS country_rank,
@current_country := country
FROM CountryCity
ORDER BY country, population DESC
) ranked
WHERE country_rank <= 2;

 

The query returns:

 


city
country population
Kalkata India 2181000
Dehli India 808000
Riyadh KSA 7825300
Madina KSA 1016800
Lahore Pakistan 8175133
Multan Pakistan 3792621

 

How It Works

Explanation of the MySQL query:

  • Session Variables

Currently MySQL does not support ROW_NUMBER() function that can assign a sequence number within a group, but as a workaround we can use MySQL session variables.

These variables do not require declaration, and can be used in a query to do calculations and to store intermediate results.

@current_country := country

This code is executed for each row and stores the value of country column to @current_country variable.

@country_rank := IF(@current_country = country, @country_rank + 1, 1)

In this code, if @current_country is the same we increment rank, otherwise set it to 1. For the first row@current_country is NULL, so rank is also set to 1.

For correct ranking, we need to have ORDER BY country, population DESC

So if we just execute the subquery:

   SELECT city, country, population, 
       @country_rank := IF(@current_country = country, @country_rank + 1, 1) AS country_rank,
       @current_country := country 
  FROM Countrycities
  ORDER BY country, population DESC

We get the list of cities ranked by population within the country:

city country population country_rank current_country
Kalkata India 2181000 1 India
Dehli India 808000 2 India
Goya India 422000 3 India
riyadh KSA 7825300 1 KSA
Madina KSA 1016800 2 KSA
Makkah KSA 770800 3 KSA
Lahore Pakistan 8175133 1 Pakistan
Multan Pakistan 3792621 2 Pakistan
Liquat Pur Pakistan 2695598 3 Pakistan
  • Selecting Range

When we have a rank assigned to each city within its country, we can retrieve the required range:

   -- Get top 2 for each country
   SELECT city, country, population
   FROM (/*subquery above*/) ranked
   WHERE country_rank <= 2;
 
   -- Get the city with 3rd population for each country
   SELECT city, country, population
   FROM (/*subquery above*/) ranked
   WHERE country_rank = 3;

ROW_NUMBER() – Oracle, SQL Server and PostgreSQL

In Oracle, SQL Server and PostgreSQL you can achieve the same functionality using ROW_NUMBER function:

   SELECT city, country, population
   FROM
    (SELECT city, country, population, 
                  ROW_NUMBER() OVER (PARTITION BY country ORDER BY population DESC) as country_rank
      FROM cities) ranked
   WHERE country_rank <= 2;

This query works in Oracle, SQL Server and PostgreSQL without any changes and returns:

city country population
Kalkata India 2181000
Dehli India 808000
Riyadh KSA 7825300
Madina KSA 1016800
Lahore Pakistan 8175133
Multan Pakistan 3792621
 
Leave a comment

Posted by on February 12, 2015 in My SQL

 

Tags: , , ,

How to show Time from DateTime Rdlc Report Field


One of my recent requirements involved retrieving just the time portion of a records value,  generally the  we have the data type saved as a date/time format. First of all we want to show only time at rdlc report . so, this is easiest way to show time or if you want to show date.

First :: For Time.

=FormatDateTime(First(Fields!LoginTime.Value, “DS”), DateFormat.LongTime)

First :: For Date.

=FormatDateTime(First(Fields!LoginTime.Value, “DS”), DateFormat.ShortDate)

Rdlc DateTime Formula

 
Leave a comment

Posted by on January 7, 2015 in Crystal Report

 

Tags: , , , ,

incorrect datetime value for function str_to_date


Hi,

when you use Mysql function “str_to_date” in Asp.net  code to merg code from one database to other and you can aslo move (map) Time along with Date . then common error occure after add time

SELECT STR_TO_DATE(‘[21/Apr/2009:07:14:50 +0100]’, ‘[%d/%b/%Y:%H:%i:%S +0100]’);

The SQLException does not come directly from MySQL, it’s probably triggered by your client language. MySQL will just generate a warning you can normally ignore. Whatever, the ALLOW_INVALID_DATESSQL mode should actually do the trick:

Warning:

mysql> SET @@SESSION.sql_mode='NO_ZERO_DATE,NO_ZERO_IN_DATE';
Query OK, 0 rows affected (0.00 sec)

mysql> insert into test (date_created) VALUES (str_to_date('','%m/%d/%Y'));
Query OK, 1 row affected, 1 warning (0.01 sec)

mysql> show warnings;
+---------+------+-------------------------------------------------------+
| Level   | Code | Message                                               |
+---------+------+-------------------------------------------------------+
| Warning | 1411 | Incorrect datetime value: '' for function str_to_date |
+---------+------+-------------------------------------------------------+
1 row in set (0.00 sec)

No warning:

mysql> SET @@SESSION.sql_mode='ALLOW_INVALID_DATES';
Query OK, 0 rows affected (0.00 sec)

mysql> insert into test (date_created) VALUES (str_to_date('','%m/%d/%Y'));
Query OK, 1 row affected (0.03 sec)
Specifier Description
%a Abbreviated weekday name (Sun..Sat)
%b Abbreviated month name (Jan..Dec)
%c Month, numeric (0..12)
%D Day of the month with English suffix (0th, 1st, 2nd, 3rd, …)
%d Day of the month, numeric (00..31)
%e Day of the month, numeric (0..31)
%f Microseconds (000000..999999)
%H Hour (00..23)
%h Hour (01..12)
%I Hour (01..12)
%i Minutes, numeric (00..59)
%j Day of year (001..366)
%k Hour (0..23)
%l Hour (1..12)
%M Month name (January..December)
%m Month, numeric (00..12)
%p AM or PM
%r Time, 12-hour (hh:mm:ss followed by AM or PM)
%S Seconds (00..59)
%s Seconds (00..59)
%T Time, 24-hour (hh:mm:ss)
%U Week (00..53), where Sunday is the first day of the week
%u Week (00..53), where Monday is the first day of the week
%V Week (01..53), where Sunday is the first day of the week; used with %X
%v Week (01..53), where Monday is the first day of the week; used with %x
%W Weekday name (Sunday..Saturday)
%w Day of the week (0=Sunday..6=Saturday)
%X Year for the week where Sunday is the first day of the week, numeric, four digits; used with %V
%x Year for the week, where Monday is the first day of the week, numeric, four digits; used with %v
%Y Year, numeric, four digits
%y Year, numeric (two digits)
%% A literal % character
%x x, for any x not listed above
 
Leave a comment

Posted by on November 13, 2014 in Uncategorized