My understanding is that it is similar to write code directly into the old "static void Main(string[] args)
" without the need to display what's above.
However, I used to declare my variables in the class Program to have them accessible from other classes (apologies if not best practice, I learnt C# by myself and as long as it works, I'm happy with my code). See example below:
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
namespace myNameSpace
{
class Program
{
//variables declaration
public static string abc = "abc";
public static int xyz = 1;
static void Main(string[] args)
{
//code goes here
}
}
}
With C# 9, it seems I can only declare variables in the Main section, so how can I declare them to be able to access them from other classes?