Archive for January, 2010

C# String Vs StringBuilder

Sunday, January 31st, 2010

In C#, the string data type is immutable. This means once a value is assigned to the variable, assigning a new value or doing any operation to the same variable creates a new memory location rather than using the same.

For example:

string myString = “My name is Khan”;

myString.ToUpper();

After running the above code, the myString variable will have still “My name is Khan”.

In C#, the StringBuilder is mutable. There are operations like Append, Remove, can be performed on a StringBuilder variable. The same memory location being used for operations. The string will grow or shrink from the same memory location.

If you want to concatenate few strings in your code, would you use string or stringbuilder? The rule of thumb you can often use is, if you are concatenating 5 or less strings, the string is okay. If it goes beyond 5, the stringbuilder is efficient.

How to change the facebook look to Vista favor?

Saturday, January 30th, 2010

Unlike other social networking site, facebook won’t allow you to change it’s skin or look. However, you can change your facebook look just for you. I have found out about this when I was doing this for my table tennis junkie facebook site.

To do this, you need a Firefox add on called stylish. Remember, this will work on Firefox browsers only. Download and install stylish add on here. After you download the stylish add on, go to your facebook home page. At the bottom of the firefox browser, you can see a S icon. Click that S icon. You will see an option ‘Find styles for this site…’ in the menu. Your click will take you to the page where many styles for Facebook are available. Select any style you like. Simply click the INSTALL WITH STYLISH button on that page.

Close the Firebox browser. Go to the Facebook website. Here you go! Your facebook has now the vista look.

C# null Vs void

Saturday, January 30th, 2010

In C#, the null is being used to assign a nothing value to a reference type variable. The void means anonymous type.

What makes a language Object Oriented?

Tuesday, January 26th, 2010

There are three qualities that make a language Object Oriented.

  1. Inheritance
  2. Encapsulation
  3. Polymorphism

Inheritance: Inheritance is the behavior of one class can inherit behavior and properties from another class.

  • Class inheritance
  • Interface inheritance

Encapsulation: Encapsulation helps encapsulate data methods and properties.

  • Data and method hiding through private access keywords.
  • Class hiding in a class hierarchy. The client does not see some class in the class hierarchy.

Polymorphism: Polymorphism is poly + morphism which is multi behaviors.

  • Overriding
  • Overloading
  • Delegates

Which is better – float or double or decimal?

Monday, January 25th, 2010

The float and double data types are floating or approximations. The float has a precision upto 32 bits. The double has precision upto 64 bits. In financial calculations where the precision is very importa, decimal is appropriate. The decimal can give precision upto 128 bits.