0

How do I call string a defined outside of the class ?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using  static2 ;

namespace static1
{
    class Program
    {

        string a = "dsfsdf";
        static void Main(string[] args)
        {

            Automobile.Drive();
            int i = Automobile.NumberOfWheels;



           // Automobile car = new Automobile.compute(2,3);


            //Console.Write(car);

            Console.WriteLine(Program.a);

        }
    }
}
5
Contributors
5
Replies
30
Views
3 Years
Discussion Span
Last Post by KM499
0

Can you rephrase your question? What string do you want to be able to access and in which class?

0

I just re-read your question. I'm confused by what you're asking. String "a" isn't defined outside of the class. It is a global variable--which is defined outside of Main. If you are trying to reference it within class "Program" do it as in my previous post.

You could potentially reference it from another class by making it "public static" as stated in a post above. You could also just make it public.

Edited by cgeier

0

You can create a public property instead of a variable of type string and put that in a public class, then you inherit that class into the one you are using and can therefore, easily access that property's value.
Hope that helps :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.