Всем доброго!!! Пытаюсь программировать на С#, но уперся уже несколько дней - не могу вызвать переменную из другого ("а") из другого класса ("Class1').
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
new Class1();
double b = Class1.a;
Console.WriteLine("a = {0}", b);
while (true)
{
try
{
string command = Console.ReadLine();
if (command == "stop")
{
break;
}
}
catch (System.Runtime.InteropServices.COMException)
{
}
}
}
}
}
Класс, от которого надо взять значение переменной "а" максимально упрощен
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
public class Class1
{
public double a = 179;
}
}
Пробовал гуглить, яндексить и т. д. - не помогло.
a
- это не переменная (локальные переменные в C# - это значения, которые вы объявляете внутри методов).a
- это поле (field) – PashaPash 2 ноя '16 в 9:17