Monday, September 3, 2018

Repeat character without loop in C#

 you can use string constructor that accepts a char and the number of times to repeat it.

Example:

public class Program
{
public static void Main()
{
string tabs = new String('X',  4);
Console.WriteLine(tabs);
}
}

OUTPUT:
XXXX

Sunday, March 25, 2018

Right and Left padding in C#

Padding adds the space or any character to the right or left side.

PadRight: This method add the characters in right side and left align
PadLeft: This method add the characters in left side and right align



Saturday, March 24, 2018

Readonly and Constant in C#

Constant: Constant fields are define at the time of declaration and once they are defined can't be changed.
NOTE:
  1. This can't be declared static.
  2. Local scope 
  3. This is implicitly static variable.
  4. This must to initialised
Readonly: Readonly can be initialised either at the time of declaration or within the constructor of the same class and change the value in the same class constructor.


Thursday, March 22, 2018

Dictionary in C#

  • Dictionary is generic collection and includes System.Collections.Generic namespace.
  • This is collection of Key and value pair and key must be a unique.
  • In the dictionary, you cannot be including duplicate key. 
  • In the dictionary, duplicate key given run time error.

NOTE:

  1. It returns error if we try to find a key which does not exist.
  2.  It is faster than a hash table because there is no boxing and unboxing.
  3. Dictionary is a generic type which means we can use it with any data type.

List<T> in C#

List
  • Lists are strongly typed generic collections.
  • They will store values of different or same datatype.
  • List size will increase or decrease dynamically.
  •  Its defined in the System.Collections.Generic namespace
      Add item in List :

Hash Table in C#

 The Hashtable is a non-generic collection and used to store the key/value pairs based on the hash code of the key. Key will be used to acce...