Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Friday, 7 July 2017

C# version history

c# net version

latest c# version is 7. C# enhanced many feature in its all version. Below are the information of major enhacement in C# in each and every version in sequence wise.

C# Version 1


When you go back and look, C# version 1 really did look an awful lot like Java.  As part of its stated design goals for ECMA, it sought to be a “simple, modern, general purpose object-oriented language.”  At the time, it could have done worse thank looking like Java in order to achieve those goals.

But if you looked back on C# 1.0 now, you’d find yourself a little dizzy.  It lacked the built in async capabilities and some of the slick functionality around generics that we take for granted.  As a matter of fact, it lacked generics altogether.  And Linq?  Nope.  That would take some years to come out.

C# version 1 looked pretty stripped of features, compared to today.  You’d find yourself writing some verbose code.  But yet, you have to start somewhere.

C# Version 2


Now things start to get interesting.  Let’s take a look at some major features of C# 2.0, released in 2005, along with Visual Studio 2005.  (Check out the book by NDepend creator Patrick Smacchia about .NET 2.0.)


  • Generics
  • Partial types
  • Anonymous methods
  • Nullable types
  • Iterators
  • Covariance and contravariance

While Microsoft may have started with a pretty generic object-oriented language, C# Version 2 changed that in a hurry.  Once they had their feet under them, they went after some serious developer pain points.  And they went after them in a big way.

With generics, you have types and methods that can operate on an arbitrary type while still retaining type safety.  So, for instance, having a List<T> lets you have List<string> or List<int>  and perform type safe operations on those strings or ints while you iterate through them.  This certainly beats creating ListInt inheritors or casting from Object for every operation.

Oh, and speaking of iterators, C# Version 2 brought iterators.  To put it succinctly, this let you iterate through the items in List (or other Enumerable types) with a foreach loop.  Having this as a first class part of the language dramatically enhanced readability of the language and people’s ability to reason about the code.

And yet, Microsoft continued to play a bit of catch up with Java.  Java had already released versions that included generics and iterators.  But that would soon change as the languages continued to evolve apart.

C# Version 3


C# Version 3 came in late 2007, along with Visual Studio 2008, though the full boat of language features would actually come with C# Version 3.5.  And what a version this proved to be.  I would go so far as to say that this established C# as a truly formidable programming language.  Let’s take a look at some major features in this version.


  • Auto implemented properties
  • Anonymous types
  • Query expressions
  • Lambda expression
  • Expression trees
  • Extension methods

In retrospect, many of these features seem both inevitable and inseparable.  In fact, I have a hard time a true headliner, since they all fit together so strategically.  Others won’t have that same problem, though.  They’ll say that C# Version 3’s killer feature was the query expression, also known as Linq (Language INtegrated Query).

I chase a little more nuance because I view expression tress, lamba expressions and anonymous types as the foundation upon which they constructed Linq.  But, in either case, we found ourselves presented with a fairly revolutionary concept.  Microsoft had begun to lay the groundwork for turning C# into a hybrid OO-functional language.

Specifically, you could now write SQL-style, declarative queries to perform operations on collections, among other things.  Instead of writing a for loop to compute the average of a list of integers, you could now do that as simply as list.Average().  The combination of query expressions and extension methods made it look as though that list of ints had gotten a whole lot smarter.

It took a little while for people to really grasp and integrate the concept, but they gradually did.  And now, years later, code is much more concise, simple, and functional.

C# Version 4


C# Version 4 would have had a difficult time living up to the groundbreaking status of version 3.  With version 3, Microsoft had moved the language firmly out from the shadow of Java and into prominence.  The language was quickly becoming elegant.

The next version did introduce some cool stuff, though.


  • Dynamic binding
  • Named/optional arguments
  • Generic covariant and contravariant
  • Embedded interop types

Embedded interop types alleviated a deployment pain.  Generic covariance and contravariance give you a lot of power, but they’re a bit academic and probably most appreciated by framework and library authors.  Named and optional parameters let you eliminate a lot of method overloads and provide convenience.  But none of those are exactly paradigm altering.

I’ll leave that distinction for the introduction of the dynamic keyword.  By doing this, Microsoft introduced into C# Version 4 the ability to override the compiler on compile time typing.  That’s right.  By using the dynamic keyword, you can now shoot yourself in the foot a la dynamically typed languages like JavaScript.  You can create a dynamic x = “a string” and then add six to it, leaving it up to the runtime to sort out what on earth should happen next.

I say that a bit tongue in cheek, obviously.  This gives you the potential for errors but also great power within the language.

C# Version 5


With C# Version 5, Microsoft released a very focused version of the language.  They put nearly all of their effort for that version into another pretty groundbreaking language concept.  Here is the major features list.


  • Asynchronous members
  • Caller info attributes

Now, don’t get me wrong.  The caller info attribute is pretty cool.  It lets you easily retrieve information about the context in which you’re running without resorting to a ton of boilerplate reflection code.  I actually love this feature.

But async and await are the real stars of this release.  When this came out in 2012, Microsoft changed the game again by baking asynchrony into the language as a first class participant.  If you’ve ever dealt with long running operations and the implementation of webs of callbacks, you probably loved this language feature.

C# Version 6


With versions 3 and 5, Microsoft had done some pretty impressive stuff in an OO language.  (Version 2 did as well, but they were fast following Java with those language features.)  With version 6, they would go away from doing a dominant killer feature and instead release a lot of features that delighted users of the language.  Here are some of them.


  • Static imports (a la Java)
  • Exception filters
  • Property initializers
  • Expression bodied members
  • Null propagator
  • String interpolation
  • nameof operator
  • Dictionary initializer

Taken individually, these are all cool language features.  But if you look at them altogether, you see an interesting pattern.  In this version, Microsoft worked really hard to eliminate language boilerplate and make code more terse and readable.  So for fans of clean, simple code, this language version was a huge win.

Oh, and they did do one other thing along with this version, though it’s not a traditional language feature, per se.  They released Roslyn the compiler as a service.  Microsoft now uses C# to build C#, and they let you use the compiler as part of your programming efforts.

C# Version 7


Finally, we arrive at C# version 7.  That’s the current version as of the writing of this post.  This has some evolutionary and cool stuff in the vein of C# 6, but without the compiler as a service.  Here are some of the new features.


  • Out variables
  • Tuples and deconstruction
  • Pattern matching
  • Local functions
  • Expanded expression bodied members
  • Ref locals and returns

All of these offer cool new capabilities for developers and the opportunity to write even cleaner code than ever.  In particular, I think Microsoft scratched some long term itches by condensing the declaration of variables to use with the “out” keyword and by allowing multiple return values via tuple.

Tuesday, 28 January 2014

stringbuilder c#

StringBuilder is a dynamic object that allows you to expand the number of characters in the string that it encapsulates. The System.Text.StringBuilder class can be used when you want to modify a string without creating a new object. For example, using the StringBuilder class can boost performance when concatenating many strings together in a loop.

Example with StringBuilder methods

Set the Capacity and Length of stringbuilder 

StringBuilder sb = new StringBuilder("Hello World!", 25);

StringBuilder.Append-Appends information to the end of the current StringBuilder


StringBuilder sb = new StringBuilder("Hello World!");
sb.Append("How are you.");
Console.WriteLine(sb);


StringBuilder.AppendFormat-Replaces a format specifier passed in a string with formatted text


int MyInt = 25;
StringBuilder sb= new StringBuilder("Your total is ");
sb.AppendFormat("{0:C} ", MyInt);
Console.WriteLine(sb);

StringBuilder.Insert-Inserts a string or object into the specified index of the current StringBuilder


StringBuilder sb = new StringBuilder("Hello World!");
sb.Insert(6,"Beautiful ");
Console.WriteLine(sb);

StringBuilder.Remove-Removes a specified number of characters from the current StringBuilder


StringBuilder sb = new StringBuilder("Hello World!");
sb.Remove(5,7);
Console.WriteLine(sb);

StringBuilder.Replace-Replaces a specified character at a specified index


StringBuilder sb = new StringBuilder("Hello World!");
sb.Replace('!', '?');
Console.WriteLine(sb);

Converting a StringBuilder Object to a String

You must convert the StringBuilder object to a String object before you can pass the string represented by the StringBuilder object to a method that has a String parameter or display it in the user interface. You do this conversion by calling the StringBuilder.ToString method.

StringBuilder.ToString() method to display the string.

StringBuilder sb = new StringBuilder("Hello World!");
string str=sb.ToString();
Console.WriteLine(str);

Monday, 6 May 2013

object oriented vs object based programming language



Object Base Language Not Support Inheritance & Polimorphisum.

Object-Based Programming usually refers to objects without inheritance and without polymorphism, These languages support abstract data types and not classes,which provide inheritance and polymorphism.

however,support both inheritance and polymorphism and they are object-oriented.

Tuesday, 9 April 2013

Bind vs Eval (Data Binder)


The data values can be retrieved with the Eval method – they cannot be modified or deleted.

The Bind method on the other hand allows for the data-bound controls to be modified in addition to retrieval, and hence is preferred over Eval method.

Wednesday, 3 April 2013

Access modifiers in c#

Visual Basic Modifier
C# Modifier
Definition
Public (Visual Basic)
public
The type or member can be accessed by any other code in the same assembly or another assembly that references it.
Private (Visual Basic)
private
The type or member can only be accessed by code in the same class.
Protected (Visual Basic)
protected
The type or member can only be accessed by code in the same class or in a derived class.
Friend (Visual Basic)
internal
The type or member can be accessed by any code in the same assembly, but not from another assembly.
Protected Friend
protected internal
The type or member can be accessed by any code in the same assembly, or by any derived class in another assembly.

Tuesday, 2 April 2013

Read tnsnames.ora in VB.NET

Below are the code for read tnsname.ora file(tns name) in vb.net. Through below functions you can get the information of the tns.

//Declare namespace
Imports System
Imports System.Collections.Generic
Imports System.Text.RegularExpressions
Imports System.IO

Public Class ReadTNS
    //Function for Load TNS Name
    Public Function LoadTNSNames() As List(Of String)
        Dim DBNamesCollection As New List(Of String)()
        Dim regPattern As String = "[\n][\s]*[^\(][a-zA-Z0-9_.]+[\s]*"
        Dim tnsNamesOraFilePath As String = GetPathToTNSNamesFile()

        If Not tnsNamesOraFilePath.Equals("") Then
            ' Verify file exists
            Dim tnsNamesOraFile As New FileInfo(tnsNamesOraFilePath)
            If tnsNamesOraFile.Exists Then
                If tnsNamesOraFile.Length > 0 Then
                    'read tnsnames.ora file                        
                    Dim tnsNamesContents As String = File.ReadAllText(tnsNamesOraFile.FullName)
                    Dim numMatches As Integer = Regex.Matches(tnsNamesContents, regPattern).Count
                    Dim col As MatchCollection = Regex.Matches(tnsNamesContents, regPattern)
                    For Each match As Match In col
                        Dim m As String = match.ToString()
                        m = m.Trim()
                        DBNamesCollection.Add(m.ToUpper())
                    Next
                End If
            End If
        End If
        Return DBNamesCollection
    End Function

   //Function for Get path of TNS File

    Private Shared Function GetPathToTNSNamesFile() As String
        Dim systemPath As String = Environment.GetEnvironmentVariable("Path")
        Dim reg As New Regex("[a-zA-Z]:\\[a-zA-Z0-9\\]*(oracle|app)[a-zA-Z0-9_.\\]*(?=bin)")
        Dim col As MatchCollection = reg.Matches(systemPath)

        Dim subpath As String = "network\ADMIN\tnsnames.ora"
        For Each match As Match In col
            Dim path As String = match.ToString() & subpath
            If File.Exists(path) Then
                Return path
            End If
        Next
        Return String.Empty
    End Function
End Class