Tuesday, 29 July 2014

Bubble Sort Using C#

Something we are calling it as sinking sort, it is simple way of sorting of repedatly steps of list to make it sort. Pass the value of list to one by one until it not swap. The way the comparison sort is similar way as bubble sort.

Bubble sort example image (from Wiki)

Find the duplicates value in Array in C#

Finding the duplicate value in array using C# code.

class Program
{
static void Main(string[] args)
{
string InuputString = "Input Array \n";
Console.WriteLine(InuputString);

ArrayList obj = new ArrayList(){"1","4","Test","^","1","67","43","4","Ret","78"};

for (int i = 0; i < obj.Count; i++)
{
Console.Write(obj[i] + " ");
}

GetDuplicateArryValue(obj);
}

public static void GetDuplicateArryValue(ArrayList arr)
{
//to store all the duplicate values in Array list
ArrayList dup = new ArrayList();

for (int i = 0; i < arr.Count; i++)
{
for (int j = i + 1; j < arr.Count; j++)
{
if (arr[i].Equals(arr[j]))
{
//When duplicate value is found, check
//whether the value not contained in the dup array list
if (!dup.Contains(arr[i]))
{
}
}
}
}
Console.WriteLine("\n Duplicates Number Are");

for (int i = 0; i < dup.Count; i++)
{
Console.Write(dup[i] + " ");
}
Console.WriteLine();
}
}

OUTPUT :

Fibonacci Series in C#

Generating the febonacci series in C#

class Program
{
static void Main(string[] args)
{
string InuputString = "Febonacci Series \n";
Console.WriteLine(InuputString);
GenerateFibonacciSeries(10);
}

public static  void GenerateFibonacciSeries(int value)
{

int ftemp = 0;

int f1 = 1;
//temporary variable
int f2 = 0;
Console.Write(f1);
//loop through all the numbers
for (int i = 0; i < value; i++)
{
//assign temporary variable
f2 = ftemp;
ftemp = f1;
f1 = f2 + ftemp;

Console.Write(" ");
Console.Write(f1);
}

}
}

Output :

C# Palindrome Code

Sample code for Palindrome  in C#.

class Program
{
static int strLen = 0;
static int numLen = 0;
static void Main(string[] args)
{
string InuputString = "Testset";
Console.WriteLine(InuputString);
ISPalindrome(InuputString);
}

public  static void ISPalindrome(string str)
{

strLen = str.Length;
str = str.ToLower();

while (numLen < strLen)
{

if (str[numLen] != str[strLen - 1])
{
Console.WriteLine("Not a Palindrome");
break;
}

else
{
numLen++;
strLen--;

if (numLen > strLen - 1)
{
Console.WriteLine("Palindrome");
}

}

}
}
}

Difference between x.equal(y) and x==y

The equal and == operator are used to compersion check and both are returning the Boolean value(true or false)

For value type both of them are working same.
e.g.
int a= 10;
int b= 10;
if(a==b) // true;
if(a.equal(b)) // true

But for reference type both of them are behaving different.

e.g
StringBuilder sb1 = new StringBuilder(“Value”);
StringBuilder sb2 = new StringBuilder(“Value”);
If(sb1 == sb2) // false
If(sb1.equal(sb2)) // true

Thursday, 3 July 2014

Could not load file or assembly 'Oracle.DataAccess, Version=4.121.1.0

Could not load file or assembly 'Oracle.DataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. The system cannot find the file specified.

It is problem due to application is not pointing to proper DDL of oracle access and your GAC is having different version of Oracle.DataAccess.

To correct this you just need to put the below code into web.config file.

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Oracle.DataAccess" publicKeyToken="89B483F429C47342"/>
<bindingRedirect oldVersion="4.121.1.0" newVersion="4.112.1.2"/>
</dependentAssembly>
</assemblyBinding
</runtime>

By doing this when application is looking to the version which is not exist then it will redirect to the exist DLL version.

Generally by doing this you can work with the two same DDL with dirffrent version and based on the requirement you can call the version of DLL