using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
public interface IabcTest
{ void modOfTwoValue(); }
/* GenericList Example */
public class GenericList
{
public void add(T input)
{ }
}
/* GenericList End Example */
class Program : IabcTest
{
public class exampleClass { }
//Readonly
//Can be either an instance member or static.
//Value is evaluated at run time.
//Can be either initialized in declaration or in the constructor.
public readonly int P = 3;
//Can't be static
//Value is evaluated at compile time.
//Can be Initiailized at declaration only.
public const int I = 14159;
//ReadOnly Example -----------
public Program()
{
Console.WriteLine("Value of Readonly" + P);
P = 20;
Console.WriteLine("Value of Readonly" + P);
}
public static int J = 5;
static void Main(string[] args)
{
#region SwapTwoValue
SwapTwoValue stv = new SwapTwoValue();
stv.SwapTwoValues();
#endregion SwapTwoValue
#region Poperties
PopertiesClassABC prop = new PopertiesClassABC();
prop.ff = 19;
Console.WriteLine("value of Proerties : " + prop.ff);
#endregion Poperties
#region FabnociSeries
FabnociSeries f = new FabnociSeries();
int s = f.Fabonicci(5);
Console.WriteLine("Pint Simple Fabonicci:" + s);
for (int i = 1; i <= 10; i++)
{
Console.WriteLine("Pint Recursive Fabonicci:=" + FabnociSeries.RecursiveFabnociSeries(i));
}
#endregion FabnociSeries
#region Star
printStar();
#endregion Star
/* GenericList Example */
GenericList<int> list1 = new GenericList<int>();
GenericList<string> list2 = new GenericList<string>();
GenericList<exampleClass> list3 = new GenericList<exampleClass>();
/* GenericList end Example */
#region Implemenation of abstract,Inharitance, override function
abcClass2 aobj = new abcClass2();
Console.WriteLine(aobj.addTwoNumber(10, 20));
#endregion Implemenation of abstract,Inharitance, override function
IabcTest pro = new Program();
pro.modOfTwoValue();
#region Singleton
Singleton s1 = Singleton.Instance();
Singleton s2 = Singleton.Instance();
if (s1 == s2)
{
Console.WriteLine("Both are Equal");
}
#endregion Singleton
#region LoadBalaance
LoadBalaance l1 = LoadBalaance.Getloadbalancer();
LoadBalaance l2 = LoadBalaance.Getloadbalancer();
LoadBalaance l3 = LoadBalaance.Getloadbalancer();
if (l1 == l2 && l2 == l3)
{
LoadBalaance balancer = LoadBalaance.Getloadbalancer();
for (int i = 0; i < 10; i++)
{
string server = balancer.Server;
Console.WriteLine("Request to" + server);
}
}
#endregion LoadBalaance
// //FileInfo f = new FileInfo(@"c:\codejava.txt");
// //f.ExistsMessage();
Console.ReadKey();
}
/* PrintStar Example --- */
static void printStar()
{
int Input = 10;
for (int i = 0; i < Input; i++)
{
int stars = 1 + 2 * (i);
int space = Input - i;
for (int j = 0; j < space; j++)
{
Console.Write(" ");
}
for (int k = 0; k < stars; k++)
{
Console.Write("*");
}
Console.WriteLine();
}
}
/* PrintStar End Example --- */
#region Implemenation of abstract,Inharitance, override function
public abstract class abcClass1
{
public abstract int addTwoNumber(int x, int y);
public abstract int multiTowNumber(int x, int y);
public int xyz()
{
int x = 0;
Console.WriteLine("Non abstract methods xyz" + x);
return x;
}
}
public class abcClass2 : abcClass1
{
public override int addTwoNumber(int x, int y)
{ return x + y; }
public override int multiTowNumber(int x, int y)
{ throw new NotImplementedException(); }
}
public abstract class abcClass3 : abcClass1
{
public override int multiTowNumber(int x, int y)
{ return x * y; }
}
#endregion Implemenation of abstract,Inharitance, override function
#region IabcTest Members
//Remender Value Get Use of % Example -----
public void modOfTwoValue()
{
Console.WriteLine("Value of Const" + I);
//Static Example -----------
Console.WriteLine("Value of Static" + J);
J = 50;
Console.WriteLine("Value of Static" + J);
Print3N5Multiple p3n5 = new Print3N5Multiple();
p3n5.Print3N5();
}
//Remender Value Get Use of % End Example -----
#endregion
}
class Print3N5Multiple
{
public void Print3N5()
{
#region Print 3 and 5
string abc = string.Empty;
for (int i = 1; i <= 100; i++)
{
if (i % 3 == 0)
{
abc = "ThumbsUp";
Console.WriteLine("Value" + i + " : " + abc);
}
else if (i % 5 == 0)
{
//abc += i + "Sachin";
abc = "Sachin";
Console.WriteLine("Value" + i + " : " + abc);
}
if (i % 3 == 0 && i % 5 == 0)
{
abc = "ThumbsUp and Sachin";
Console.WriteLine("Value" + i + " : " + abc);
}
}
Console.ReadLine();
#endregion Print 3 and 5
}
}
class SwapTwoValue
{
#region Swaptwo values
/* Swaptwo values Example --- */
public void SwapTwoValues()
{
int a = 10;
int b = 50;
a = b + a;
b = a - b;
a = a - b;
Console.WriteLine("Value of a " + a);
Console.WriteLine("Value of b " + b);
float x = 10.5f;
float y = 50.5f;
x = x * y;
y = x / y;
x = x / y;
Console.WriteLine("Value of x " + x);
Console.WriteLine("Value of y " + y);
/* Swaptwo values End Example --- */
#endregion Swaptwo values
}
}
/* Poperties Example ---- */
class PopertiesClassABC
{
int f1;
public int ff
{
get { return f1; }
set { f1 = value; }
}
}
/* Poperties End Example ---- */
/* FabnociSeries Example ---- */
class FabnociSeries
{
public int Fabonicci(int n)
{
int Previous = -1;
int next = 1;
for (int i = 0; i < n; i++)
{
int sum = next + Previous;
Previous = next;
next = sum;
Console.WriteLine(next);
}
return next;
}
#region Recursive program to compute RecursiveFabnociSeries numbers
//Recursive program to compute RecursiveFabnociSeries numbers
public static int RecursiveFabnociSeries(int n)
{
if (n == 0 || n == 1)
{ return n; }
else
{ return RecursiveFabnociSeries(n - 1) + RecursiveFabnociSeries(n - 2); }
}
#endregion Recursive program to compute RecursiveFabnociSeries numbers
}
/* FabnociSeries End Example ---- */
/* Singleton Example ---- */
class Singleton
{
private static Singleton _instance;
protected Singleton()
{ }
public static Singleton Instance()
{
if (_instance == null)
{
_instance = new Singleton();
}
return _instance;
}
}
class LoadBalaance
{
private static LoadBalaance _instance;
private List<string> _server = new List<string>();
private Random _random = new Random();
private static object syncLock = new object();
protected LoadBalaance()
{
_server.Add("server1");
_server.Add("server2");
}
public static LoadBalaance Getloadbalancer()
{
if (_instance == null)
{
lock (syncLock)
{
if (_instance == null)
{ _instance = new LoadBalaance(); }
}
}
return _instance;
}
public string Server
{
get
{
int r = _random.Next(_server.Count);
return _server[r].ToString();
}
}
}
//Singleton end Example ----
//public static class myExtenstion
//{
// public static string ExistsMessage(this FileInfo f)
// {
// Console.WriteLine("FileInfo.Exists={0}", f.Exists);
// Console.WriteLine("FileInfo.Exists={0}", f.Length);
// Console.ReadLine();
// return f.Exists.ToString();
// }
//}
}