Thursday, February 9, 2017

Hash table in C#



In C# hash table is the collection of key or values, which is used to map a key to value. We can use any non-null object as a key; we can retrieve the items from hash table by providing key.
The common function used in hash table is given below:

Add – used to add a pair of value to Hashtable
Syntax
HashTable.Add (Key, Value)
Hashtable h;
h.Add(“1”, “Sachin”);
  
ContainsKey – used to checked a specified key exist or not.
Syntax
bool HashTable.ContainsKey (key)
h.contains(“1”);

ContainsValue - used to checked a specified value exist or not.
Syntax 
bool HashTable.Containsvalue (value)
h.containsvalue(“Sachin”);

Remove – used to delete specified key or values.
Syntax 
HashTable.Remove(key)
h.remove(“1”)

Wednesday, February 1, 2017

Create a clone of asp controls in asp .net C# on button click

Create a clone of asp controls in asp .net C# on button click

I have faced a real time issue at my website, on button click the page creates duplicate control at my website. After searching, I found  that I have missed closing tag of div, so any html tag if you missed occur duplicate control generation problem.


Solution  : Missed any html closing tag.

Wednesday, January 18, 2017

What is tuple and how to declare it?



A tuple is s new data type introduced in .Net Framework 4.0. It is used when we want to store multiple values having different data type and without having a class to store the value, in this situation the tuple is best option. In other words a Tuple is a container that contains similar or different data type (7 items) and 1 Tuple.

Declaration of Tuple

The declaration of the Tuple is similar to dictionary <tkey, tvalue>
Tuple<t1>
Tuple<t1, t2, t3>
Tuple<t1, t2, t3, t4>
Tuple<t1, t2, t3, t4, t5>
Tuple<t1, t2, t3, t4, t5, t6>
Tuple<t1, t2, t3, t4, t5, t6, t7>
Tuple<t1, t2, t3, t4, t5, t6, t7, tRest>
T is any data type and tRest a tuple type.

Tuesday, January 17, 2017

Deconstruction in C# 7.0



 Deconstruction is a process of split a variables value into parts and store it on new variables. It is important when a variable stores multiple values such as tuple.
The method GetATuple returns a tuple with three values.

Example:
(string name, string city, int sal) GetATuple(int id)
{
String name =string.empty;
String city=string.emplty;
Int sal=0;
If (id ==1000)
{
name=”Sachin”;
city=”Kanpur”;
sal=2000;
}
return(name, city, sal)
}