Register Framework 4 for IIS hosting

%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i

Leave a comment

Posted by on April 2, 2014 in .NET


Get factors of a number

int n = 10;
List<int> factors = new List<int>();

int max = Convert.ToInt32(Math.Sqrt(n));

for (int i = 1; i <= max; i++)
if (n % i == 0)
if (i != max) // add square-root factors only once.
factors.Add(n / i);

Leave a comment

Posted by on December 21, 2013 in .NET


Difference between String and string

1. String stands for System.String and it is a .NET Framework type.
2. string is a type in C#. System.String is a type in the CLR.
3. string is an alias in the C# language for System.String. Both of them are compiled to System.String in IL      (Intermediate Language),
4. so there is no difference. Choose what you like and use that.
5. string is an alias for String in the .NET Framework.
6. for code in C#, its prefer to use string as it’s a C# type alias and well-known by C# programmers.

7. string is a reserved word, but String is just a class name.This means that ‘string’ cannot be used as a          variable name by itself.

StringBuilder String = new StringBuilder(); // compiles
StringBuilder string = new StringBuilder(); // doesn’t compile

8. If you really want a variable name called ‘string’ you can use @ as a prefix :
StringBuilder @string = new StringBuilder(); this applies to string also.

9. so String is not a keyword and it can be used as Identifier whereas string is a keyword and cannot be                 used as Identifier. And in function point of view both are same.
10. you can’t use String without using System; but string can use without that namespace.
11. static functions such as String.Format, String.Join, String.Concat, String.isNullOrWhitespace etc… are             from String.
I can say the same about (int, System.Int32) etc..

Leave a comment

Posted by on December 21, 2013 in .NET, ASP.NET,


default Timeouts in c#

SqlConnection.ConnectionTimeout – 15 sec

- Gets the time to wait while trying to establish a connection before terminating the attempt.

SqlCommand.CommandTimeout - 30 seconds

- Gets or sets the wait time before terminating the attempt to execute a command

Session Timeout – 20 mins

<SessionState timeout=”10”></SessionState>

Cookies per Domain – 20 – 1KB


Leave a comment

Posted by on December 20, 2013 in .NET, ASP.NET,


PrimaryKey vs UniqueKey

Primary Key:
Primary Key enforces uniqueness of the column on which they are defined.
Primary Key creates a clustered index on the column.
Primary Key does not allow Nulls.


Alter table with Primary Key:

Unique Key:
Unique Key enforces uniqueness of the column on which they are defined.
Unique Key creates a non-clustered index on the column.
Unique Key allows only one NULL Value.

Alter table to add unique constraint to column:

Leave a comment

Posted by on December 20, 2013 in SQL SERVER


String Vs StringBuilder

1. String is immutable. It means that you can’t modify string at all, the result of modification is new string. This is not effective if you plan to append to string
2. many actions that you do with string
3. Here concatenation is used to combine two strings by using String object
4. The first string is combined to the other string by creating a new copy in the memory as a string object, and then the old string is deleted
5. string is non updatable
6. everytime a object has to be created for Operations like append,Insert etc. at runtime

1. StringBuilder is mutable. It can be modified in any way and it doesn’t require creation of new instance.
2. if you try to do some other manipulation (like removing a part from the string, replacing a part in the string, etc.), then it’s better not to use StringBuilder at those places. This is because we are anyway creating newstrings.
3. system.stringbuilder is updateble
4. string builder is faster than the string object
5.String builder is more efficient in case large amount of string operations have to be perform.
6.Insertion is done on the existing string.
7. At the end, we can get the string by StringBuilder.ToString()
1. We must be careful to guess the size of StringBuilder. If the size which we are going to get is more than what is assigned, it must increase the size. This will reduce its performance.
2. many actions can’t be done with StringBinder.
3. When initializing a StringBuilder, you are going down in performance.
4. StringBuilder can be used where more than four or more string concatenations take place.

Leave a comment

Posted by on December 20, 2013 in .NET, ASP.NET,, Console Applications


Tags: , ,

Update alternate rows in sqlserver

update s set recstatus=’I’ from
(select row_number() over (order by id) sno,* from mastertbl)s
where sno%2=0


with c as (
select row_number() over (order by id) sno,* from mastertbl
) update c set recstatus=’I’ where sno%2=0

Leave a comment

Posted by on August 20, 2013 in .NET, SQL SERVER


Get every new post delivered to your Inbox.

%d bloggers like this: