Skip to main content

Posts

Showing posts from January, 2016

SQL Server "Primary Key", "Unique Key" and "Foreign Key" [Database]

The PRIMARY KEY and UNIQUE KEY both are similar and it used to apply the uniqueness of the columns and   also used for uniquely identify each row in database tables. The major difference between Primary key, Unique key and Foreign Key as given below.             Primary Key 1.        A primary key cannot accept null values.            2.        A primary key must be unique. 3.        By default,  primary key create only one clustered index in the database . 4.        Each table can have one and only one primary key. 5.        Each table can have one and only one clustered index. 6.        Primary key can be made foreign key into another table. 7.        PK support auto increments. Unique Key 1.        A unique key can accept only single null value. 2.        A unique key does not have to be the primary key. 3.        By default, unique key create non-clustered index. 4.        Each table can have more than one unique key. 5.        Unique ke

Count character occurrence of a string using dictionary KeyValuePair C#?

Hello everyone, I am going to share the code sample for find and count the characters of a string using dictionary key value pair. The example as given below. /// <summary> /// Count character occurrence of a string using dictionary KeyValuePair C#? /// </summary> public class CountCharsOccurrence {     static void Main( string [] a)     {         Dictionary < char , int > dicList = new Dictionary < char , int >();         Console .WriteLine( "Enter charater sting" );         foreach ( var chr in Console .ReadLine())         {             int count = 0;             if (dicList.ContainsKey(chr))             {                 count = dicList[chr];             }             dicList[chr] = count + 1;         }         foreach ( KeyValuePair < char , int > pair in dicList)         {             Console .WriteLine(pair.Key + " = " + pair.Value);         }         Console

Find the most occurrence of a character in string C#?

Hello everyone, I am going to share the code sample for find the most occurrence of a character in string using ASP.Net C# . The example in detail with output as given below. public class CountMostOccurrenceCharacters { static void Main( string [] ss) {     Dictionary < char , int > dicList = new Dictionary < char , int >();     int last = 0;     Console .WriteLine( "Enter the charactor string" );     foreach ( char chr  in Console .ReadLine())     {         int  count;         dicList.TryGetValue( chr  , out  count);          count ++;         if ( count  > last)         {             last =  count ;         }         dicList[ chr  ] =  count ;     }     foreach ( KeyValuePair < char , int > charList in dicList)     {          if (charList.Value == last)         {             Console .WriteLine( "{0}: {1}" , charList.Key, charList.Value);         }     }     Console .Rea

Reverse string in with and without using reverse function in C#

Hello everyone, I'm sharing the code sample for Reverse strings and numbers with and without using the  reverse function .  The example in detail is given below. Example 1, Using for loop /// REVERSE STRIG WITH USING C# FUNCTIONS public class ReverseStrigs {      static void Main( string [] a)     {     Console .WriteLine( "Enter string for Reverse" );         string str = Console .ReadLine();         Console .WriteLine( Reverse (str));         Console .ReadLine();     }     public static string Reverse( string str)     {         return new string (str.Reverse().ToArray());     } } /// REVERSE STRIG WITHOUT USING C# FUNCTIONS. public class ReverseStrigs {      static void Main( string [] ax)     {     Console .WriteLine( "Enter string for Reverse" );         string str = Console .ReadLine();         Console .WriteLine(Reverse(str));         Console .ReadLine();     }     public