Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace constrctovrload
{
class Program
{
static void Main(string[] args)
{
addition add1 = new addition(10);
addition add2 = new addition(10,20);
addition add3 = new addition(12,20.56,-5.40);
addition add4 = new addition(1.23F,3,565.4f,45F);


Console.Write Line(add1.result1);
Console.Write Line(add2.result2);
Console.Write Line(add3.result2);
Console.Write Line(add4.result2);

Console.Read Line();

}
}

class addition
{
public int num1;
public double num2;
public double num3;
public float num5;
public float num6;
public float num7;
public float num8;
public int result1;
public double result2;



public addition(int number1)
{
num1 = number1;
result1=num1;
}

public addition(double number1, double number2)
{
num2 = number1;
num3 = number2;
result2 = num2 + num3;
}

public addition(int number1, double number2, double number3)
{
num1 = number1;
num2 = number2;
num3 = number3;
result2 = num1 + num2 + num3;
}



public addition(float number1, int number2, float number3, float number4)
{

num5 = number1;
num6 = number2;
num7 = number3;
num8 = number4;
result2 = num5 + num6 + num7 + num8;

}
}
}
Posted
Comments
Innocent910 21-Aug-13 2:29am    
give me a rite answer
S.P.Tiwari 21-Aug-13 2:49am    
i am not getting you what you mean..?
the way you are given input it will work fine. it will call the appropriate constructor.

is am right ..?
Innocent910 21-Aug-13 3:00am    
yeah its working fine but i want to take input from user, he enter whatever he wants and on bahalf of that value only that constructor to be called whose data type match with the input value.... m not going to show all constructor values but just one the user input ??
Innocent910 21-Aug-13 3:02am    
here this program shows all constructor values rite.... but i want to take input from user and just want to show that constructor values whose data type match with the input value... u get my point ????
S.P.Tiwari 21-Aug-13 3:38am    
yeah i got the point.
why not you enforce user to enter the value in float.
i mean just convert the entered number into float if its not converting then give the message to user to enter right value.

you should also consider the position of value entered with the constructor overload arguments.

isn't the answer ..?

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900