Reputation: 27
I Want to call a class into the Main method.. And I'm getting this error :s
Code:
using System;
namespace AddMinusDivideMultiply
{
class Program
{
public static int i, j;
public static void Main()
{
Console.Write("Please Enter The First Number :");
string temp = Console.ReadLine();
i = Int32.Parse(temp);
Console.Write("Please Enter The Second Number :");
temp = Console.ReadLine();
j = Int32.Parse(temp);
Minuz.minus(); // Here its generating an Error - Error 1 The name 'Minuz' does not exist in the current context
}
}
class Terms
{
public static void Add()
{
int add;
add = Program.i + Program.j;
Console.WriteLine("The Addition Of The First and The Second Number is {0}", add);
}
class Minuz
{
public static void Minus()
{
int minus;
minus = Program.i - Program.j;
Console.WriteLine("The Subraction Of The First and The Second Number is {0}", minus);
}
}
}
}
Upvotes: 0
Views: 381
Reputation: 4052
Unless its a typo, you're missing a closing bracket for the Terms
class. The way its currently written in your post, you would need to put this statement in your Main
method:
Terms.Minuz.Minus();
Upvotes: 0
Reputation: 273169
You have embedded the Minuz
class inside the Terms
class. If you make it public class Minuz
you can call
Terms.Minuz.Minus();
to solve the error. But you probably want to move the Minuz class out of Terms.
Upvotes: 1
Reputation: 158289
The problem is that the class Minuz
is declared inside the class Terms
, and it is private
. This means that it is not visible from the Main method.
There are two possible ways to solve it:
Minuz
internal
or public
and chance the call to the Minus
method to Terms.Minuz.Minus()
Minuz
out from the Terms
class so that it is instead declared in the namespace.Also, as pointed out by others; mind the case of the method name. That will be your next problem once the class visibility has been fixed.
Upvotes: 1
Reputation: 3974
That's because the Class Minuz
is defined inside the Class Terms
so it really is not defined in the context you are trying to use it.
You did not close the definition of Terms
before declaring Minuz
Upvotes: 1
Reputation: 630339
Case matters in C#!
Call this:
Minuz.Minus();
Also, need to change your braces so it's not inside Terms:
class Terms
{
public static void Add()
{
int add;
add = Program.i + Program.j;
Console.WriteLine("The Addition Of The First and The Second Number is {0}", add);
}
}
class Minuz
{
public static void Minus()
{
int minus;
minus = Program.i - Program.j;
Console.WriteLine("The Subraction Of The First and The Second Number is {0}", minus);
}
}
Upvotes: 2