I am just trying to figure out the technical reason why in the below some lines do not end with a semicolon but other lines do - what is it about a semicolon that C# expects in some lines then others....
In fact whilst writing this I noticed that the statements that have to have curly brackets {} do not need semicolons but the lines that are on its own "Console.WriteLine" do need it.
Really trying to find the technical reasons for this...
ie:
namespace checkPackage **//no semicolon**
{
class Program **//no semicolon**
{
static void Main(string[] args) **//no semicolon**
{
listFilesInDirectory(@"C:Temp"); **//NEEDS a semicolon**
}
static void listFilesInDirectory(string workingDirectory) **//no semicolon**
{
string[] filePaths = Directory.GetFiles(workingDirectory); **//NEEDS a semicolon**
foreach (string filePath in filePaths) **//no semicolon**
{
Console.WriteLine(filePath); **//NEEDS a semicolon**
}
}
}
}
See Question&Answers more detail:os