tags:

views:

82

answers:

4

I have 3 classes named maths, alphabets and main. The Maths Class contains Add function and alphabet class contains a function same as Maths class. But the third class is for calling the function which is used for calling the above functions defined in the above classes.

How it will work?

+2  A: 

If the functions are static you'll have to explicitly tell which class they belong to - the compiler will be unable to resolve otherwise:

Maths.Add();

If they are not static the compiler will determine this based on the object type:

Maths maths = new Maths();
maths.Add();  // the necessary class and function will be resolved automatically
sharptooth
A: 

By using an interface that defines an Add function and having Math and alphabets implement that interface.

ozczecho
A: 

C# programs do not contain "functions", but instead methods, which are attached to classes. So you call Math.Add or Alphabet.Add. Conflicting function names do not exist, in C#, for that reason. Conflicting class names are resolved by name spaces.

ammoQ
A: 

Is this what you mean?

public class Maths
{
    public Maths() { }
    public Double Add(Double numberOne, Double numberTwo)
    {
        return numberOne + numberTwo;
    }
}

public class Alphabet
{
    public Alaphabet() { }
    public String Add(Char characterOne, Char characterTwo)
    {
        return characterOne.ToString() + characterTwo.ToString();
    }

}

public void Main()
{
    Alphabet alaphatbet = new Alphabet();
    String alphaAdd = alphabet.Add('a', 'b'); // Gives "ab"

    Maths maths = new Maths();
    Double mathsAdd = maths.Add(10, 5); // Gives 15
}
Chalkey