26 July 2011

palindrome in console applications


string str = string.Empty;
            Console.WriteLine("Enter a String");
            string s = Console.ReadLine();
            int i = s.Length;
            for (int j = i - 1; j >= 0; j--)
            {
                str = str + s[j];
            }
            if (str == s)
            {
                Console.WriteLine(s + " is palindrome");
            }
            else
            {
                Console.WriteLine(s + " is not a palindrome");
            }

factorial of number in console applications


            int count = 1;
            Console.Write("Enter Number for factorial: ");
            int number = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= number; i++)
            {
                count = count * i;
            }
            Console.Write(count);
            Console.Read();

or
          public static long numfact(long n)
          {
           if (n <= 1)
               return 1;
           else
             return n * numfact(n - 1);
           }
           Console.Write(numfact(5));

palindrome in console applications


string str = string.Empty;
            Console.WriteLine("Enter a String");
            string s = Console.ReadLine();
            int i = s.Length;
            for (int j = i - 1; j >= 0; j--)
            {
                str = str + s[j];
            }
            if (str == s)
            {
                Console.WriteLine(s + " is palindrome");
            }
            else
            {
                Console.WriteLine(s + " is not a palindrome");
            }

factorial of number in console applications


            int count = 1;
            Console.Write("Enter Number for factorial: ");
            int number = Convert.ToInt32(Console.ReadLine());
            for (int i = 1; i <= number; i++)
            {
                count = count * i;
            }
            Console.Write(count);
            Console.Read();

or
          public static long numfact(long n)
          {
           if (n <= 1)
               return 1;
           else
             return n * numfact(n - 1);
           }
           Console.Write(numfact(5));

21 July 2011

Some Coding Standards in .net

1.    Use Meaningful, descriptive words to name variables. Do not use abbreviations.
    Good:
    string address
    int salary
     Not Good:
           string name
       string addr
      int sal

2. Do not use single character variable names like i, n, s etc. Use names like index, temp
     variable 'i' is used for for iterations in loops
        Ex:  for ( int i = 0; i < count; i++ ){....}

3.  Do not use underscores (_) for local variable names. But member variables must be prefixed with underscore (_)

4.  Prefix boolean variables, properties and methods with “is” or similar prefixes.
      Ex: private bool _isFinished

5.  File name should match with class name.
       Ex:  for the class HelloWorld, the file name should be helloworld.cs (or, helloworld.vb) 

6.  Keep private member variables, properties and methods in the top of the file and public members in the bottom.  

7. Use String.Empty instead of “”
      Ex: txtMobile= String.Empty;

8.   8. Avoid having very large files. If a single file has more than 1000 lines of code, it is a good candidate for refactoring. Split them logically into two or more classes.

9. Use StringBuilder class instead of String when you have to manipulate string objects in a loop. The String object works in weird way in .NET. Each time you append a string, it is actually discarding the old string object and recreating a new object, which is a relatively expensive operations.

20 July 2011

Some Coding Standards in .net

1.    Use Meaningful, descriptive words to name variables. Do not use abbreviations.
    Good:
    string address
    int salary
     Not Good:
           string name
       string addr
      int sal

2. Do not use single character variable names like i, n, s etc. Use names like index, temp
     variable 'i' is used for for iterations in loops
        Ex:  for ( int i = 0; i < count; i++ ){....}

3.  Do not use underscores (_) for local variable names. But member variables must be prefixed with underscore (_)

4.  Prefix boolean variables, properties and methods with “is” or similar prefixes.
      Ex: private bool _isFinished

5.  File name should match with class name.
       Ex:  for the class HelloWorld, the file name should be helloworld.cs (or, helloworld.vb) 

6.  Keep private member variables, properties and methods in the top of the file and public members in the bottom.  

7. Use String.Empty instead of “”
      Ex: txtMobile= String.Empty;

8.   8. Avoid having very large files. If a single file has more than 1000 lines of code, it is a good candidate for refactoring. Split them logically into two or more classes.

9. Use StringBuilder class instead of String when you have to manipulate string objects in a loop. The String object works in weird way in .NET. Each time you append a string, it is actually discarding the old string object and recreating a new object, which is a relatively expensive operations.

Naming conventions in .net

Pascal case
The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized.
Example:
BackColor, DataSet
Camel case
The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized.
Example:
numberOfDays, isValid
Uppercase
All letters in the identifier are capitalized.
Example:
ID, PI
1).  Private Variables: _strFirstName, _dsetEmployees
2).  Local Variables: strFirstName, dsetEmployees
3).  Namespace:(Pascal) System.Web.UI, System.Windows.Forms
4).  Class Naming:(Pascal) FileStream, Button
5).  Interface Naming:(Pascal) IServiceProvider, IFormatable
6).  Parameter Naming:(Camel) pTypeName, pNumberOfItems
7).  Method Naming:(Pascal) RemoveAll(), GetCharAt()
7).  Method Parameters:(Camel) void SayHello(string name)....
8).  Property / Enumerations Naming:(Pascal) BackColor, NumberOfItems
9).  Event Naming:(Pascal) public delegate void MouseEventHandler(object sender, MouseEventArgs e);
10).  Exception Naming: catch (Exception ex){ }
11).  Constant Naming: AP_WIN, CONST

19 July 2011

Naming conventions in .net

Pascal case
The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized.
Example:
BackColor, DataSet
Camel case
The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized.
Example:
numberOfDays, isValid
Uppercase
All letters in the identifier are capitalized.
Example:
ID, PI
1).  Private Variables: _strFirstName, _dsetEmployees
2).  Local Variables: strFirstName, dsetEmployees
3).  Namespace:(Pascal) System.Web.UI, System.Windows.Forms
4).  Class Naming:(Pascal) FileStream, Button
5).  Interface Naming:(Pascal) IServiceProvider, IFormatable
6).  Parameter Naming:(Camel) pTypeName, pNumberOfItems
7).  Method Naming:(Pascal) RemoveAll(), GetCharAt()
7).  Method Parameters:(Camel) void SayHello(string name)....
8).  Property / Enumerations Naming:(Pascal) BackColor, NumberOfItems
9).  Event Naming:(Pascal) public delegate void MouseEventHandler(object sender, MouseEventArgs e);
10).  Exception Naming: catch (Exception ex){ }
11).  Constant Naming: AP_WIN, CONST

keyboard key ascii values


<script type="text/javascript">
document.onkeyup = KeyCheck;

function KeyCheck()
{
var KeyID = event.keyCode;
switch(KeyID)
{
case 16:
document.Form1.KeyName.value = "Shift";
break;
case 17:
document.Form1.KeyName.value = "Ctrl";
break;
case 18:
document.Form1.KeyName.value = "Alt";
break;
case 19:
document.Form1.KeyName.value = "Pause";
break;
case 37:
document.Form1.KeyName.value = "Arrow Left";
break;
case 38:
document.Form1.KeyName.value = "Arrow Up";
break;
case 39:
document.Form1.KeyName.value = "Arrow Right";
break;
case 40:
document.Form1.KeyName.value = "Arrow Down";
break;
}
}

how to make nvarchar id auto incerement (1) function in sqlserver

create function idincr() returns nvarchar(50)
as begin
declare @id int, @cid nvarchar(50), @did int
set @id=(select count(*) from tblcust)
if(@id>0)
begin
set @did= (select max(cast(substring(custid,2,len(custid))as int))from tblcust)+1;
set @cid='A'+cast(@did as nvarchar(50))
end
else 
set @cid='A1'
return @cid
end

Go

select dbo.idincr()

Go

how to change the database name in sqlserver using query

ALTER DATABASE databasename MODIFY NAME = newdatabasename

how to Insert data of one database table to another database table

INSERT INTO Database2..Table1 SELECT * FROM Database1..Table1

How to restore and backup database in sqlserver using query

For BackUp:
backup database mydb to disk = 'c:\mydb.bak'


For Restore:
restore database mydb from disk = 'c:\mydb.bak'

keyboard key ascii values


<script type="text/javascript">
document.onkeyup = KeyCheck;

function KeyCheck()
{
   var KeyID = event.keyCode;
   switch(KeyID)
   {
      case 16:
      document.Form1.KeyName.value = "Shift";
      break; 
      case 17:
      document.Form1.KeyName.value = "Ctrl";
      break;
      case 18:
      document.Form1.KeyName.value = "Alt";
      break;
      case 19:
      document.Form1.KeyName.value = "Pause";
      break;
      case 37:
      document.Form1.KeyName.value = "Arrow Left";
      break;
      case 38:
      document.Form1.KeyName.value = "Arrow Up";
      break;
      case 39:
      document.Form1.KeyName.value = "Arrow Right";
      break;
      case 40:
      document.Form1.KeyName.value = "Arrow Down";
      break;
   }
}</script>

how to make nvarchar id auto incerement (1) function in sqlserver

create function idincr() returns nvarchar(50)
as begin
declare @id int, @cid nvarchar(50), @did int
set @id=(select count(*) from tblcust)
if(@id>0)
begin
set @did= (select max(cast(substring(custid,2,len(custid))as int))from tblcust)+1;
set @cid='A'+cast(@did as nvarchar(50))
end
else 
set @cid='A1'
return @cid
end

Go

select dbo.idincr()

Go