Showing posts with label DOTNET. Show all posts
Showing posts with label DOTNET. 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.

Wednesday, 3 April 2013

Access modifiers in c#

Visual Basic Modifier
C# Modifier
Public (Visual Basic)
The type or member can be accessed by any other code in the same assembly or another assembly that references it.
Private (Visual Basic)
The type or member can only be accessed by code in the same class.
Protected (Visual Basic)
The type or member can only be accessed by code in the same class or in a derived class.
Friend (Visual Basic)
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 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()
                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
        Return String.Empty
    End Function
End Class

Monday, 24 December 2012

Difference between beginexecutereader and executereader (beginexecutereader Vs executereader)

The BeginExecuteReader(...) and EndExecuteReader...() are for performing the
ExecuteReader(...) method asynchronously. If you use ExecuteReader(...)
your thread is blocked while that method executes.

Using BeginExecuteReader(...) (and the corresponding EndExecuteReader(...))
ExecuteReader(...) will be executed in a seperate thread, allowing for
yours to continue processing. The BeginExecuteReader(...) method will
require a callback method, and in that callback method, you will make a
call to EndExecuteReader(...) to end the asynchronous operation, and
retreive the return value.

Wednesday, 5 December 2012

Difference between thread and process


Threads share the address space of the process that created it.
Threads have direct access to the data segment of its process.
Threads can directly communicate with other threads of its process.
Threads have almost no overhead.
New threads are easily created.
Threads can exercise considerable control over threads of the same process
Changes to the main thread (cancellation, priority change, etc.) may affect the behavior of the other threads of the process.


Processes have their own address.
Processes have their own copy of the data segment of the parent process.
Processes must use inter-process communication to communicate with sibling processes.
Processes have considerable overhead.
New processes require duplication of the parent process.
Processes can only exercise control over child processes.
Changes to the parent process does not affect child process.

Difference between trace and debug in .NET

This class works only when your application build defines the symbol TRACE.
For tracing, you have to use Trace.WriteLine statements.
Trace class is generally used to trace the execution during deployment of the application.
Trace class works in both debug mode as well as release mode.
Performance analysis can be done using Trace class.
Trace runs in a thread that is different from the Main Thread.
Trace is used during Testing Phase and Optimization Phase of different releases.

This class works only when your application build defines the symbol DEBUG.
For debug, you have to use Debug.WriteLine statements.
You generally use debug classes at the time of development of application.
Debug class works only in debug mode.
Performance analysis cannot be done using Debug class.
Debug runs in the same thread in which your code executes.
Debug is used during Debugging Phase.

Monday, 1 October 2012

Wcf vs Web services

Web service:
The File extension of web service is .asmx.
It can be hosted in IIS.
[WebService] attribute has to be added to the class.
[WebMethod] attribute represents the method exposed to client.
One-way, Request- Response are the different operations supported in web service.
System.Xml.serialization name space is used for serialization.
XML 1.0, MTOM(Message Transmission Optimization Mechanism), DIME, Custom.
Hash Table cannot be serialized.
Only public properties/fields can be serialized.
Unhandled Exceptions returns to the client as SOAP faults.
Slower than WCF.
Uses only SOAP(Simple Object Access Protocol).

The file extension of WCF service is .svc.
It can be hosted in IIS, windows activation service, Self-hosting, Windows service.
[ServiceContraact] attribute has to be added to the class.
[OperationContract] attribute represents the method exposed to client.
One-Way, Request-Response, Duplex are different type of operations supported in WCF.
System.Runtime.Serialization namespace is used for serialization.
XML 1.0, MTOM, Binary, Custom.
The DataContractSerializer translate the Hash table into the XML.
Public/Private properties/fields can be serialized.
Better than WebService. The performance measures in terms of xml serialization.
It can send/receive message in any transport protocol message format. By default it uses SOAP for communication.

Friday, 28 September 2012

Unable to start debugging. The Silverlight managed debugging package isn’t installed.

If you ever get the message, well you probably have a configuration problem. So just download and install the Silverlight Developer Run time.

You can get it from here :

It works for me.

Wednesday, 5 September 2012


By "conversion" mean converting one datatype to another (e.g. string to
integer, decimal to integer, object to string etc).

By "cast" mean changing one type of object into another type that is
related to it by one of the following rules.

Wednesday, 30 May 2012

Response.Redirect Vs Server.Transfer

Response.Redirect simply tells the browser to visit another page.

Server.Transfer helps reduce server requests, keeps the URL the same and, allows you to transfer the query string and form variables

Response.Redirect simply sends a message down to the browser, telling it to move to another page.

Server.Transfer conserves server resources. Instead of telling the browser to redirect, it simply changes the "focus" on the Web server and transfers the request.

which therefore eases the pressure on your Web server and makes your applications run faster.

can't use Server.Transfer to send the user to an external site. Only Response.Redirect can do that

Server.Transfer maintains the original URL in the browser. This can really help streamline data entry techniques, although it may make for confusion when debugging

The Server.Transfer method also has a second parameter—"preserveForm". If you set this to True, using a statement such as Server.Transfer("WebForm2.aspx", True), the existing query string and any form variables will still be available to the page you are transferring to.

So, in brief: Response.Redirect simply tells the browser to visit another page.
Server.Transfer helps reduce server requests, keeps the URL the same and,  allows you to transfer the query string and form variables.

State management

State management is the process by which you maintain state and page information over multiple requests for the same or different pages.

Types of State Management

There are 2 types State Management: 

1. Client – Side State Management 
This stores information on the client's computer by embedding the information into a Web page, a uniform resource locator(url), or a cookie. The techniques available to store the state information at the client end are listed down below:

a. View State – Asp.Net uses View State to track the values in the Controls. You can add custom values to the view state. It is used by the page framework to automatically save the values of the page and of each control just prior to rendering to the page. When the page is posted, one of the first tasks performed by page processing is to restore view state.

b. Control State – If you create a custom control that requires view state to work properly, you should use control state to ensure other developers don’t break your control by disabling view state.

c. Hidden fields – Like view state, hidden fields store data in an HTML form without displaying it in the user's browser. The data is available only when the form is processed.

d. Cookies – Cookies store a value in the user's browser that the browser sends with every page request to the same server. Cookies are the best way to store state data that must be available for multiple Web pages on a web site.

e. Query Strings - Query strings store values in the URL that are visible to the user. Use query strings when you want a user to be able to e-mail or instant message state data with a URL.

2. Server – Side State Management

a. Application State - Application State information is available to all pages, regardless of which user requests a page.

b. Session State – Session State information is available to all pages opened by a user during a single visit.

Both application state and session state information is lost when the application restarts. To persist user data between application restarts, you can store it using profile properties.


Advantages of Client – Side State Management:

1. Better Scalability: With server-side state management, each client that connects to the Web server consumes memory on the Web server. If a Web site has hundreds or thousands of simultaneous users, the memory consumed by storing state management information can become a limiting factor. Pushing this burden to the clients removes that potential bottleneck.

2. Supports multiple Web servers: With client-side state management, you can distribute incoming requests across multiple Web servers with no changes to your application because the client provides all the information the Web server needs to process the request. With server-side state management, if a client switches servers in the middle of the session, the new server does not necessarily have access to the client’s state information. You can use multiple servers with server-side state management, but you need either intelligent load-balancing (to always forward requests from a client to the same server) or centralized state management (where state is stored in a central database that all Web servers access).

Advantages of Server – Side State Management:

1. Better security: Client-side state management information can be captured (either in transit or while it is stored on the client) or maliciously modified. Therefore, you should never use client-side state management to store confidential information, such as a password, authorization level, or authentication status.

2. Reduced bandwidth: If you store large amounts of state management information, sending that information back and forth to the client can increase bandwidth utilization and page load times, potentially increasing your costs and reducing scalability. The increased bandwidth usage affects mobile clients most of all, because they often have very slow connections. Instead, you should store large amounts of state management data (say, more than 1 KB) on the server

Reference URL

Thursday, 17 May 2012

Override machine.config connection string with web.config connection string

Add <clear /> tag in web.config for Override machine.config connection string with web.config
connection string

    <clear />
     <add key="ConnectionString" value="...." />

Monday, 7 May 2012

Visual Studio 2011 New Editor Features

To add a asp:DetailsView, all I typed was <dv, and it’s there for you.
You can extract a snippet of html to a user control
Just ‘space’ after the backgrouund-color property and you’ll see a popup for you to choose from. This is the CSS Color Picker!
If you press on the plus sign, a detailed version of the color picker shows up. Once I moved the opacity slider, the value changes to a rgba() function. NEAT!
I typed in the xml documentation for my divide javascript method and when I call it in the testDivide function, I can see the XML documentation give details about my divide function.
Also, after typing the function call, I press ‘.’ and I can see VS is detecting the return value of my divide function and gives me other functions that I can apply on a Number type.
I can do an F12 and go to the definition of any function.
This one just blew my mind off. I see intellisense even on overloaded js functions.Brilliant!

Friday, 27 April 2012

Install / Uninstall .NET Windows Service

Install service using InstallUtil.exe
To install or uninstall windows service (which was created using .NET Framework) use utility InstallUtil.exe. This tool can be found in the following path (use appropriate framework version number).


To install .NET service run command similar to this (specify full path to your service).

InstallUtil.exe "path of service"

To uninstall .NET service use the same command with parameter /u.

InstallUtil.exe /u "path of service"

Wednesday, 22 February 2012

Regex for eight character with one Special character,one Capital alphabet and one numeric

Regex for eight character with one Special character,one Capital alphabet and one numeric

Dim regexCheck As Regex = New Regex("^.*(?=.{8,})(?=.*\d)(?=.*[A-Z])(?=.*[!@#$%^&+=]).*$")

Tuesday, 21 February 2012

Get current page name in ASP.NET

The below code is for get current page name in application:

string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;

System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);


Asp.Net temporary files

ASP.NET provides the HttpRuntime.CodeGenDir property which gets the physical path to the directory where ASP.NET stores temporary files for the current application.


Running this on my machine and get the output (where temporary file stored).

Wednesday, 15 February 2012

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster


Post back before the form has finished rendering.


In web.confog use below key

<pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode ="Never" />

Sunday, 13 November 2011

GMT value in Dotnet

We can get GMT value by using utcnow() inbulid function of dotnet framework.

For example see below image which is executed in LINQpad.

Sunday, 30 October 2011

Common Exception Classes in .NET

Common Exception Classes:

The following exceptions are thrown by certain C# operations.

Thrown when an attempt to allocate memory (via new) fails.
System.OutOfMemoryExceptionThrown when the execution stack is exhausted by having too many pending method calls; typically indicative of very deep or unbounded recursion.
System.NullReferenceExceptionThrown when a null reference is used in a way that causes the referenced object to be required.
System.TypeInitializationExceptionThrown when a static constructor throws an exception, and no catch clauses exists to catch in.
System.InvalidCastExceptionThrown when an explicit conversion from a base type or interface to a derived types fails at run time.
System.ArrayTypeMismatchExceptionThrown when a store into an array fails because the actual type of the stored element is incompatible with the actual type of the array.
System.IndexOutOfRangeExceptionThrown when an attempt to index an array via an index that is less than zero or outside the bounds of the array.
System.MulticastNotSupportedExceptionThrown when an attempt to combine two non-null delegates fails, because the delegate type does not have a void return type.
System.ArithmeticExceptionA base class for exceptions that occur during arithmetic operations, such as DivideByZeroException and OverflowException.
System.DivideByZeroExceptionThrown when an attempt to divide an integral value by zero occurs.
System.OverflowExceptionThrown when an arithmetic operation in a checked context overflows.