So in this code block from my console application, when ran, should move the 'X' in Class02 up and down when you hit the respective arrow keys but it doesn't, it just stays in place:
class Program
{
static void Main(string[] args)
{
Class01.Function01();
}
}
class Class01
{
public int num01 = 5;
public int num02 = 5;
public static void Function01()
{
while (true)
{
Class02.Function02();
}
}
}
class Class02
{
public static void Function02()
{
var c1 = new Class01();
Console.SetCursorPosition(c1.num02, c1.num01);
Console.Write("X");
ConsoleKeyInfo keyInfo;
keyInfo = Console.ReadKey(true);
switch (keyInfo.Key)
{
case ConsoleKey.UpArrow:
c1.num01--;
break;
case ConsoleKey.DownArrow:
c1.num01++;
break;
}
}
}
I know what's wrong here, the int in Class01 is not being changed in class02. therefore the Cursor Position is still set as 5 5 writing the 'X' in the same place every key stroke.
So, how does one change the value of int num01 in Class02?
Thanks for any help with this.
num01andnum02are. But I would immediately interpretXandYas a set of coordinates. Similarly, compareClass01andCursor. Once your codebase expands to business level complexity, or you need to revisit code that you've not touched for a long time, you'll understand why clear naming is needed in order to not have to figure out from scratch what's going on.