Subhash Sharma

Subhash Sharma
Subhash Sharma

This is Subhash Sharma(Software Engineer) Blog

Welcome to this blog and find every solution.............

Search This Blog

Software Engineer(Subhash Sharma)

Software Engineer(Subhash Sharma)
Software Engineer

Sunday, November 14, 2010

Distinct Value from two array

string[] a1 = { "A", "B", "A", "C", "C" };
string[] a2 = { "A", "E", "C", "D", "C" };
// var unique = a1.Union(a2);
string[] a3 = new string[a1.Length + a2.Length];
a1.CopyTo(a3, 0);
a2.CopyTo(a3, a1.Length);
ArrayList arr = new ArrayList();

for (int k = 0; k < a3.Length; k++)
{
arr.Add(a3[k].ToString());
}
for (int i = 0; i < arr.Count - 1; i++)
{
for (int j = i + 1; j < arr.Count; j++)
{
if (arr[i].Equals(arr[j]))
{
arr.RemoveAt(j);
}
}
}
for (int i = 0; i < arr.Count; i++)
{
arr.Sort();
Console.WriteLine(arr[i]);
}
Console.ReadLine();

Distinct Value from two array(Linq)

string[] a1 = { "A", "B", "A", "C", "C" };
string[] a2 = { "A", "E", "C", "D", "C" };
var unique = a1.Union(a2);

Wednesday, November 10, 2010

AutoIncremented Number

public string NewRequestID()
{
string NewID = "";
SqlDataAdapter da = default(SqlDataAdapter);
DataTable dt = null;
da = new SqlDataAdapter("select top 1 code from EmpMaster order by code desc", con);
dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count != 0)
{
string str = dt.Rows[0]["Code"].ToString();
int i = Convert.ToInt32(str.Substring(1));
NewID = (i + 1).ToString();
int start = NewID.Length + 1;
//Position from where 0 has to be inserted to the RequestID.
for (int j = start; j <= (str.Length - 1); j++)
{
NewID = "0" + NewID;
}
NewID = "A" + NewID;
}
else
{
NewID = "A000001";
}
return NewID;
}