Existing rule:
Place members in a well-defined order (AV2406)
Maintaining a common order allows other team members to find their way in your code more easily. In general, a source file should be readable from top to bottom, as if reading a book, to prevent readers from having to browse up and down through the code file.
New language features to consider:
- local functions
They can be declared anywhere in method bodies (this includes property/event accessors, anonymous methods, lambda expressions and other local functions)
Based on the guidance "a source file should be readable from top to bottom" I think its best to require their declaration at least below its first usage. Example:
public void M()
{
string userInput = ReadText();
string ReadText()
{
return Console.ReadLine();
}
if (userInput == "X")
{
return;
}
else
{
Console.WriteLine("You typed: " + userInput);
}
}
But I think the code becomes more readable if they are declared at the end, after all executable code. Example:
public void M()
{
string userInput = ReadText();
if (userInput == "X")
{
return;
}
else
{
Console.WriteLine("You typed: " + userInput);
}
string ReadText()
{
return Console.ReadLine();
}
}
Existing rule:
Place members in a well-defined order (AV2406)Maintaining a common order allows other team members to find their way in your code more easily. In general, a source file should be readable from top to bottom, as if reading a book, to prevent readers from having to browse up and down through the code file.New language features to consider:
They can be declared anywhere in method bodies (this includes property/event accessors, anonymous methods, lambda expressions and other local functions)
Based on the guidance "a source file should be readable from top to bottom" I think its best to require their declaration at least below its first usage. Example:
But I think the code becomes more readable if they are declared at the end, after all executable code. Example: