Jul 072017

You may ask what is the purpose of this post. The title seems really confusing indicating that i may have used the same word twice and trying to explain the difference between it. The thing is these are two different things. One if the native class string and the other is the class object provided by the framework called String. Basically there is no difference in them as  far as the functionality is concerned but when it comes to coding convention then if you want to declare any string value you should use the class ‘string’ to declare it but if you want to use any functionality from the string class the you should use the class ‘String’ which is also the class the object the static class through which you class access method like concat or Parse.

 Posted by at 10:44 pm
Jul 062017

In this post i am going to explain two different ways to parse XML file. I am directly going to start with the code but before that here is my sample XML. In the code there are two ways of parsing the XML one is the simple way of doing it through which it is done using the XMLReader way and the other is to deserialize it to a class. Both are explained below


The code to parse it is

In the above code the first method called from main is ParseXML. In this method we are using the simplest way to parse the XML by using the XMLReader. So first we need to create the XMLReader by providing the content of the XML and once we have that then its really easy to go though the XML. The first method used is ‘ReadToFollowing’ this method will take you to the first requested node and each call will traverse to the next occurrence. It returns a bool type based on the result of the search. MoveToFirstAttrubute read the first attribute of the node.

The other way to parse the XML file is to serialize it in object. But you have to have an class object in which you can map the XML file and for complex object its a bit hard to make it. Luckily VS provides a really easy way to do it. All you have to do is select the XML and do the following process


You will get the following file

In method serializeXML i am using the deserializer to deserialize the XML to catalog object and then i just loop around the list to display





 Posted by at 2:45 pm
Jul 052017

I was always getting confused in what to use until i came to know when should we use IEuqatable and IComparable. So lets say you have an object and you want to use it in a dictionary. Sometime we implement the ‘contains’ method from the dictionary on the list. Now this method wont work if the object is not implementing IEquatable. When you implement that method than the purpose of this method is to compare the object with another object. So indirectly we helped our ‘contains’ method which will use this to compare the object.


Now lets say there is another requirement in which you want to sort the dictionary then then object used in that dictionary should implement IComparable. By using this interface you will have to implement the compareTo method where you will mention the position of the two objects under observation.

 Posted by at 11:30 am
Jul 042017

I realy want to get my hands dirty with the new .Net core hype so i thought may be not its the time. Before going crazy on the visual studio i decided to use the .net core using the command line. So lets start

To begin with you need to have .net installed. If you have VS 2017 then .Net core is already part of it but if you dont have it you can download it from here 

To verify if you have successfully installed .net core open command prompt and run the command dotnet you will get this


I will do it in certain steps so that it is more clear

Step 1:

Lets create a directory where we work in so i will create a new directory called ‘dotnetHelloWorld’


Step 2:

Lets create our first project. Now we can create differnt types of project in c#, F# and VB but lets start by creating a C# console project and for that we need to run the command ‘dotnet new console’.


In our directory there will be two files created



Now lets build the project so for that we need to run the command ‘dotnet build’ and when i did that i got some errors. if you see the error list it complains about the types not defined and it cannot find the library for those system types


To fix that we need to restore before build which will restore all the required nuget packages. So run ‘dotnet restore’


Step 4:

Lets give another try to build the project so run ‘dotnet build’ and you will get this


After building now we will try to run it and if you notice the file structure there is no exe file generated in the bin folder that you can double click and run its only the pdb and the dll as .net core will generate the libraries so how to run it? Well dotnet core have solved this problem by giving a command so if you run ‘dotnet run’ you will see the output.




The reason to use it via the command is that it could be used on any platform and could be really handy on build machines.



 Posted by at 4:40 pm
Jul 032017

A quick reference on how you can use tasks. I wont write much around here as the code is explaining it self. The name of the methods tell the action around the task, how they were created and what is the purpose of that code. This is really basic code snippet right now but i will write more around that and more detailed code


 Posted by at 12:59 pm
Apr 282017

So I had a problem where I need to use the sqlBulk to insert multiple records from a data table to database. Now we are using NHibernate but sometime we don’t always use it or not truly use the NHibernate entities instead sometime we use Sqls directly either in new ado connection or using the NHibernate session.

Problem: So we had a module which was using a mixture of both some read data was done using the NHibernate session and some bulk inserts were done in a new ado connection obviously that was a bug so I thought of fixing it to use NHibernate throughout.


Use the ado connection do everything in one transaction and commit.

Use NHibernate session and do everything in that so that if this module is called from another place it could use the same session


Now as you can see from option 2 you can easily spot that the if another module is calling this module using its own session (say NHibernate) the ado wont respect that and it will open a new connection. If the caller module is not using NHibernate than it should inject the connection down the line.


I am not saying that picked up the best solution but I decided to use NHibernate session and sqlBulk using connection form NHibernate connection. So, all the things went smooth until I hit two walls

  1. A piece of code using an ado connection and a transaction
  2. Sql bulk copy

So for the first one I need a connection from NHibernate Session and a transaction. To get ado connection from NHibernate session this helped me


And it’s perfectly ok if you don’t want any transient error handling but if you do want that then this won’t give you any as by using the connection this way you sacrificed the transient handling. But I fixed that using this code

Off course you have to define SqlAzureTransientErrorDetectionStrategyWithTimeout your self.

The other sub problem was to get a transaction now you can’t have a beginTransaction on the connection. As you can’t create parallel transaction using the NHibernate connection. So what you have to do is enlist your command in ITransaction from the session so this should work like this

I used the same strategy in the bulk which was like this before my fix

And after my fix it looked like this

 Posted by at 4:38 pm
Mar 032017

The override modifier is used to extend the functionality of an abstract or virtual method. To easy understand this consider the following example.

In this example the base class is abstract along with two methods one is abstract and the other is virtual. When we use inherit from this base class we are bound to override the ‘Act’ method which is tagged as abstract. But we really don’t have to modify the functionality of the virtual method. But if we want to modify the functionality of the virtual method we just either implement it or use a ‘new’ keyword to implement the new functionality.


If you use conventional inheritance and still want to override to modify the behavior of existing base class method you can do so by using the New keyword consider the following example.

 Posted by at 2:25 pm
Dec 022016

There are certain situations where you only want to use generics types for certain types. Mean you want to limit it to be used for certain types only. Consider the following example where we have a two class CurrentEmployee and ExEmployee and we want to limit our SuperPerson to use type that are only CurrentEmployee because in my company only those person can be super persons who are currently working with us :). We use the key word where to write the name of the class. Now this could be a name of the class, an interface implemented certain classes, a base class or a struct.


 Posted by at 11:49 am
Jul 112016
A few days back i got the idea of figuring our how much time was i spending on different application while working. So i made this small console application its not perfect but it can give you a head start. So i am using the following three classes there is no complex code but still i will try to explain it.
In this test app i am only five applications so the moment it collects the data for five applications it will exit but you can always extend it.


This is the main thread that is monitoring the application and checking if thee application is started and if it is it will log it and start a time against it.


This helper class is just collecting data for different application and adding the total time being used.


 Posted by at 9:13 am
Jul 022016

In the first post we have created a DB using c#. Now this time we will drop a DB I have divided the code in to two classes so lets see them in detail.

The first class is the control class through which we will call the helpers. In the code below first we will try to connect to the master DB. In dropDatabse method we need to check if the DB exists or not and if it does then we will need to set the DB online. The reason to set the DB online is when you drop the DB then the file on the disk will also be deleted.


The helper class ExecuteSql have all the helper functions. The class is described below.

All you need to do is change the name of the DB, user id and password.

 Posted by at 7:03 pm