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);

        }
    }
}

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

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 2 Years Ago by cgeier

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 article has been dead for over six months. Start a new discussion instead.