Objective of this example:
  • constructor overloading
  • creating many instances of constructor, like classes.
  • guide with if else logic
  • Use Convert.ToInt32 to get the character value

 using System;
//mehtod overloading
// csc construct_overload_instance.cs
public class cso_1
{
public double d;
public int n1 ;
public cso_1() { Console.WriteLine("Constrcutor no param evoked"); Console.ReadLine();}
~cso_1() { Console.WriteLine("Destructor evoked");}
public cso_1(int n)
{
n1 = 10 + n ;
Console.WriteLine("--" + n1);
Console.ReadLine();
}
public cso_1(double dy)
{
d = 10 + dy ;
Console.WriteLine("Double constructor : " + read(dy));
}
public cso_1(double dy, int n)
{
d = n + dy ;
}
public cso_1(Char ch)
{
Console.WriteLine("Constuctor Ch");
Console.ReadLine();
//double read =Convert.ToDouble(ch);
// d = 10 + read ;
// ToInt32(read);
}
public static double read (double value){ Console.WriteLine("Got double "+ value); return value + 2; }


public void method(int x ){ Console.WriteLine( x + n1);}

}
////
class test
{
static void Main()
{

//Console.Write("Enter integer : " );
//do
//{
int x = 0;
string str ="";
cso_1 cs = new cso_1();
Console.Write("Enter a character: ");
char c = (char)Console.Read();
if (Char.IsUpper(c))
{
Console.WriteLine("Character is uppercase.");
str = c.ToString();
//creating new instances of constructor with new key word.
cs = new cso_1(c);
}
else if (Char.IsLower(c))
{
Console.WriteLine("Character is lowercase.");
str = c.ToString();
cs = new cso_1(c);
}
else if (Char.IsDigit(c))
{
Console.WriteLine("Character is a number.");
x = Convert.ToInt32(c);
cs = new cso_1(x);
Console.Write("Like to try double yes or no : ");
string ss = Console.ReadLine();
if (ss == "yes"){ Console.Write("enter double no error check : ");
double dd = double.Parse(Console.ReadLine());
cs = new cso_1(dd);
}
}
else
{
Console.WriteLine("Character is not alphanumeric.");
}
Console.ReadLine();
}}
 

In case you did not want to enter double