.NET Hawa

Performace Grading in Integer Conversions

  As we are working with .Net, libraries will also have similar meathods for perform single operation we need to know what is the better one and what is a big one. I searched over internet and here i am explaining giving information about some known meathods, Integer.Parse(), Convert.ToInt32(),Integer.TryParse().


Integer.Parse() method should have argument as String datatype. It will parse the string for integer value. If it has no integer value or it contains mixture of integer and characters it will throw you a exception.


Integer.Parse(string S)


Integer.TryParse takes arugments as string and an Integer. This fucntion will return boolean value. This function will work same as Integer.Parse() but it will not throw any exception. If string does not contains any integer value it will return false.

Integer.TryParse(String S, Out Integer I)


This will work as same as Integer.Parse(). So I am not explaining more about this. Convert.Toint32() aceepts null as a argumnet. Integer.Parse() will accept. Convert.ToInt32() internally calls Integer.Parse()

The main difference is taking out with the performance

Integer.TryParse() > Convert.Toint32() > Integer.Parse()

Because Integer.Parse() will throws exception when it has string or null value. Convert.toInt32() check for null string if it is null it will directly throw exception and if it is not null it will call integer.parse() meathod. Integer.TryParse() will try to parse all values and returns boolean values.

Leave a comment »

Mutable and Immutable objects.

While Learning a concept, my strong belif is bottom-up approch is better than top-down approch which gives clear idea. First I will start with Immutable type objects. An Immutable type object means the object which cannot change it’s state once it is created. In some cases, an object is considered immutable even if some internally used attributes change but the object’s state appears to be unchanging from an external point of view. Immutable objects are often useful because they are inherently thread safe.

Immutable objects are sole property of OOP Concepts.Before the advent of OOP, values held in program variables whose content never changed were known as ‘constants’ to differentiate them from variables that could be altered during execution. Examples might include conversion factors from kilogram weights to pounds or the value of Pi to several decimal places. In most object-oriented languages, objects can be referred to using references. Some examples of such languages are Java, C++, C#, VB.NET, and many scripting languages, such as Python and Ruby. In this case, it matters whether the state of an object can vary when objects are shared via references. If an object is known to be immutable, it can be copied simply by making a copy of a reference to it instead of copying the entire object. Because a reference (typically only the size of a pointer) is usually much smaller than the object itself, this results in memory savings and a boost in execution speed.

Immutable objects can be useful in multi-threaded applications. Multiple threads can act on data represented by immutable objects without concern of the data being changed by other threads. Immutable objects are therefore considered to be more thread-safe than mutable objects.

Some of the Examples in different langaugaes:


A classic example of an immutable object is an instance of the Java String class.
String s = “ABC”;

The method toLowerCase() will not change the data “ABC” that s contains. Instead, a new String object is instantiated and given the data “abc” during its construction. A reference to this String object is returned by the toLowerCase() method. To make the String s contain the data “abc”, a different approach is needed.

s = s.toLowerCase();

Now the String s references a new String object that contains “abc”. There is nothing in the syntax of the declaration of the class String that enforces it as immutable; rather, none of the String class’s methods ever affect the data that a String object contains, thus making it immutable.
By default, fields and local variables are mutable. They can be made immutable using the final keyword.

final int j = 42;
j = 43; // does not compile


Best example for Immutable in C# is String Class.

C# Supports Immutability with two key words const and readonly. They are used by the C# compiler to ensure that the state of a field won’t be changed once an object is created.

Mutable Objects:

Mutable Objects are complety opposite to immutable objects where we can modified any where.

Leave a comment »

Welcome for unidentified programmer

As a Software Engineer I was satisfied with present programming language I am using.  As a .net Programmer I was much satisfied.  I remember my first lecturer I heard in my middle of bachelor’s degree I used to do RMI programs in my lab.  I was much interested to know “How RMI Programs goanna work ?”.  I completed that task and did practices and learn that they will go by “Delegates” which represents work of a function in .NET Technology.

After 2 Years, I completed my bachelor’s degree I did not guess that I will become a .net programmer.  When I joined in my first work place my team lead told me to learn ASP and Later on ASP.net with C#.  There I learn Programming of C# programs and latest technological practices which are helpful for good programming.  So, now I am starting this blog to share my knowledge with you all.