Category Archives: C#

Generate WebReferance Proxy using wsdl.exe

To generate web reference for you project use wsdl.exe and then including the generated file (.cs) into your project.

Based on the .NET framework version your wsdl.exe file will exist in corresponding path as below

In case anyone using VS 2008 (.NET v3.5) is also looking for the wsdl.exe.
I found it here:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\wsdl.exe

Future versions C:\Program Files\Microsoft SDKs\Windows\vx.xx\bin\wsdl.exe

For v4.5.1
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\wsdl.exe

For v4.6.1
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\wsdl.exe

Using any one of below command can generate proxy class

wsdl /language:CS /n:”<NameSpaceName>” <Path of wsdl file>.wsdl

wsdl.exe /language:CS <Path of wsdl file>.wsdl

wsdl.exe <Path of wsdl file>.wsdl


How to sign and verify data using digital certificate

While communicate with other there would be a sensitive data which need to reach the other end in secure manner.

Digitally signed data comes in to picture which provide us a secure and confidential way to communicate.

Below are the code to digitally sign the plain text and send it over other end, there signed data will be verified using the public key.

To sign and verify the data we need Private and Public key. I am going to use Private key to sign the text and using public key I am going to validate the signed text.

Certificate Encrypt and Decrypt using SHA1 algorithm



Signing text using Private Key


Verify signed text in other end using public key



Hashtable in C#

Hashtable objects are quite similar to an ArrayList object except that it is not required to use a numerical index. Instead, we can use a texture key that can be

Benefits of Hashtable

  1. Insert Elements: you can add as many pairs of key/value elements as required. You do not have to specify the size ahead of time.
  2. Non-numeric index: you can use text, number and dates as your key (index).
  3. Faster Lookup: the hashtable collection caters very fast lookup of elements.
  4. Flexibility when Removing elements: you can remove any element from an Arraylist very easily

Limitations of Hashtable

  • Key must be unique: The Hashtable stipulates the key uniqueness requirement that is very cumbersome to manipulate.
  • No useful sorting: Sorting is not done by using keys or values. The items in the Hashtable are sorted internally to make it easy to find objects very quickly.
  • Performance: Although the lookup is very quick in a Hashtable, the CLR must do quite a lot of work to maintain them that is very resource-intensive.

Hashtable obj = new Hashtable();
Obj[“in”] = “india”;
Obj[“en”] = “England”;
Obj[“us”] = “USA”;

Obj[Convert.ToDateTime(“21/12/2012”)] = “The Judgment day”;

string Country = Convert.ToString(obj[“in”]);

ArrayList in C#

Benefits of Array List

  1. Insert Elements: An Array List starts with a collection containing no elements. You can add them in any position as you choose them.
  2. Automatic Resizing: you do not need to specify the array size; as you add elements, the array automatically ensures there is enough memory for the array.
  3. Flexibility When Removing Elements: you can remove any element from an Array list very easily.

Limitations of Array List

The flexibility of Array List comes at a cost of performance. Since memory allocation is a very expensive business, the fixed number of elements of the simple array
makes it much faster to work with.


ArrayList obj = new ArrayList();



Abstract Class features

  • class members that are incomplete and must be implemented in a derived class.
  • An abstract class cannot be instantiated.
  • The purpose of an abstract class is to provide a common definition of a base class that multiple derived classes can share.
  • Abstract classes may also define abstract methods.

public abstract class A
public abstract void DoWork(int i);

  • Derived classes of the abstract class must implement all abstract methods.
  • When an abstract class inherits a virtual method from a base class, the abstract class can override the virtual method with an abstract method.
  • We can also inherit normal method in the abstract class and declare it as abstract, though it compiles it shows warning that abstract method must be virtual.

public class D
public virtual void DoWork(int i)
// Original implementation.

public abstract class E : D
public abstract override void DoWork(int i);

public class F : E
public override void DoWork(int i)
// New implementation.

  • If a virtual method is declared abstract, it is still virtual to any class inheriting from the abstract class.
  • A class inheriting an abstract method cannot access the original implementation of the method.
  • override keyword  should be used while defining abstract method in derived class.


Default Access Modifiers in C#

Non Nested type 

                    | Default   | Permitted declared accessibilities
namespace            | public    | none (always implicitly public)

enum                 | public    | none (always implicitly public)

interface            | internal  | public, internal

class                | internal  | public, internal

struct               | internal  | public, internal

delegate             | internal  | public, internal

Nested Type
                     | Default   | Permitted declared accessibilities
namespace            | public    | none (always implicitly public)

enum                 | public    | none (always implicitly public)

interface            | public    | none

class                | private   | All¹

struct               | private   | public, internal, private²

delegate             | private   | All¹

constructor          | protected | All¹

interface member     | public    | none (always implicitly public)

method               | private   | All¹

field                | private   | All¹

user-defined operator| none      | public (must be declared public)

¹ All === public, protected, internal, private, protected internal

² structs cannot inherit from structs or classes (although they can, interfaces), hence protected is not a valid modifier


Nullable type

Normally we are expert in using value types like int, bool, decimal types.But those types dont have null values by default. Suppouse if you want to insert null value to database for above value types.


Boolean variable can have two values: true and false. There is no value that signifies “undefined” (null). Suppose you want to insert null value in the database column for Boolean value then there is no direct option to store null value since i have only two values: true and false.

bool boolIsNull= null; // Not Possible

To handle this kind of values .NET give us a very useful tool to for this: nullable types.

Nullable<T> //Nullable<int> or Nullable<decimal>
bool? boolIsNull= null; //Correct



Difference between Class and Structure

Classes are Reference types and Structures are Values types.

Classes are reference types, basically they will contain the address of an instance variables.

Class SimpleClass
Public int Value; 	

This the simple class am assigning value to Object to it.

Static Public void Main (string [] arg)
SimpleClass objSimpleClass1=new SimpleClass();
SimpleClass objSimpleClass2= new SimpeClass();


after in next step we change it to 10 in the object objSimpleClass2.  Since both object refer the same address, changes happened in the objSimpleClass2 or in last step that value will reflect in other object also.

What is Boxing and UnBoxing

Converting a value type to reference type is called Boxing.


int i = 12;
object box = i;

Converting a reference type to value type is called UnBoxing.


object box = 12;
int i = (int)box;

Difference Between StringBuilder and String



While concatenate two strings, a new copy in the memory will be created and old string object will be deleted this called ‘IMMUTABLE’. Normally the performance will be slow.


Normally we use Append() to concatenate the string. combining two string will be take place existing string object. No new memory will be created for this stringBuilder object and its more efficient.



%d bloggers like this: