Jump to content

C# Class Doubt 01

- - - - -

  • Please log in to reply
2 replies to this topic

#1
gautham

gautham

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts
namespace ConsoleApplication26

{

    class Program

    {

        string type = "Guitar";

        int cost = 90;


        string infotype()

        {

            return type;

        }


        int infocost()

        {

            return cost;

        }

        static void Main(string[] args)

        {

            Program m1 = new Program();


            Console.WriteLine(m1.infotype());


            Console.WriteLine(m1.infocost());

        }

    }

}

How can i use the above class(Program) in another Program?

#2
TheCompBoy

TheCompBoy

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 272 posts
A program can't have two main methods i think so if you would like to use this class in another "Program" or Project (not sure what you mean) you would have to rewrite the main method into something else.. And then maybe copy paste into a new class in the project that you're working with.
Thats how i would do it. Totaly depends on what you're trying to do.
Think my post we're usefull? Please take your time and press the Like button at my post, Big Thanks!
For great C# & Android tutorials visit my blogg: http://www.thecompboy.com/

#3
gautham

gautham

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts
@TheCompBoy's:

Thanks mate, let me re try.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users