I'm still quite new to coding in general, and while this simple program is only meant to be a test to learn how constructors work, I'd still like to know why I'm getting this error.
using System;
public class methodTest
{
int a;
int b;
int c;
public methodTest(int i, int j, int k)
{
a = i;
b = j;
c = k;
}
}
public class methodObj
{
static void Main()
{
methodTest obj = new methodTest(10, 20, 30);
Console.WriteLine("obj = " + obj.b);
Console.ReadKey();
}
}
I'm not entirely sure why I'm getting the error. The problem is with the Console.WriteLine, where it states it cannot access obj.b. The variables seem to be declared within a public class, so why can they not be accessed? I tried searching for a solution to this, but all the questions I found were much too convoluted for me to get an answer I could translate to my own understanding.
All help appreciated!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…