Need Help With a Simple C# Program!

TΞΞNSTAR™

Member
Mar 19, 2008
15,866
42
0
StuCk In My AnGelZ HeArT!!!
Guys Another Prob :(

I Want to call a class into the Main method.. And im 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);
[COLOR=Red][B]
            Minuz.minus();[/B][/COLOR]  // 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);
        }
    }
    }
}
 

digitaldjs

Member
Aug 11, 2007
926
36
0
TΞΞNSTAR™;6834256 said:
Guys Another Prob :(

I Want to call a class into the Main method.. And im 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);
[COLOR=Red][B]
            Minuz.minus();[/B][/COLOR]  // 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);
        }
    }
    }
}

try this:

public static 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);
}
}
 

¤--bACarDi--¤

Well-known member
  • Jan 9, 2009
    12,130
    288
    83
    124.43.xxx.xxx
    TΞΞNSTAR™;6834530 said:
    Nah its Minuz.minus in the correct case.. :s ah yeh nah execute the file u shud call it to the main method na ! correct me if if i am wrong!

    oh damn sorry man. it should be. cuz its a static method, my bad lol

    hold on man. installing VS restart needed :dull:
     

    koondeGoda

    Member
    Nov 28, 2007
    4,892
    35
    0
    ₪ Hyper_Cube ₪
    this works ! i modified it

    Code:
    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);
                Terms.Minus();    
    
    
            }
        }
    
        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);
            }
    
            
                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);
                }
            }
     

    koondeGoda

    Member
    Nov 28, 2007
    4,892
    35
    0
    ₪ Hyper_Cube ₪
    TΞΞNSTAR™;6834843 said:
    YEHH :) ts working now.. but what was the problem earlier?? :s

    machan you have included a inner class Minus inside Test i think that wouldnt have been necessary or correct syntax in C# (itz possible in java though) ,

    you could have seprate classes for addition and subtsractions etc if you want :)
     

    homoelectronics

    Well-known member
  • Nov 23, 2006
    1,326
    58
    48
    Avoid static methods and classes as much as possible. It is not a good idea if you are going to re-use the same component (class/method) in different places. Think you need to check little bit about variable scope/visibility and access control kind of things. If you are studying the particular language first learn those theories rather than just fixing the code. Otherwise you'll face lot difficulties in your future work without these basic concepts. ;)
     
    Last edited:

    TΞΞNSTAR™

    Member
    Mar 19, 2008
    15,866
    42
    0
    StuCk In My AnGelZ HeArT!!!
    Avoid static methods and classes as much as possible. It is not a good idea if you are going to re-use the same component (class/method) in different places. Think you need to check little bit about variable scope/visibility and access control kind of things. If you are studying the particular language first learn those theories rather than just fixing the code. Otherwise you'll face lot difficulties in your future work these basic concepts. ;)

    Yeah thats true.. I need to be more firm in the concepts.. thank you bro.. ill talk it as a advice :)
     

    ¤--bACarDi--¤

    Well-known member
  • Jan 9, 2009
    12,130
    288
    83
    124.43.xxx.xxx
    oh lol u messed up the curly braces didn't u ? or u tried to implement a inner class ? If u wanna implement inner classes u need to use inheritance. "extends" the child class