Expanded upon guideline info

- Fixed scope example to be wrapped in a class. Aside from that, it's solid.
This commit is contained in:
Tony Bark 2025-02-06 10:27:37 -05:00
parent 252db96518
commit c5960f9f6c

View file

@ -1,6 +1,8 @@
# NASA-style Programming for C#
I asked the AI to write their instructions in the form of guidelines. I figured I'd use C# since it's both my preferred language and the syntax should be fairly easy to grasp once you understand the basics. My only request was to apply .NET 6's [top-level statements](https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/top-level-statements) for brevity. Aside from that, it all works flawlessly.
I asked the AI to write their instructions in the form of guidelines. I figured I'd use C# since it's both my preferred language and the syntax should be fairly easy to grasp once you understand the basics.
My only request was to apply .NET 6's [top-level statements](https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/top-level-statements) for brevity. Aside from a few organizational tweaks with the guidelines and fixing the scope example to be wrapped in a class, it all works flawlessly.
## 1. Write Clear, Well-Structured, and Maintainable Code
@ -88,18 +90,22 @@ using (var reader = new StreamReader("example.txt"))
**Example:**
```csharp
void Main()
{
int a = 5, b = 3;
Console.WriteLine($"Sum: {Add(a, b)}");
namespace Application;
// 'a' and 'b' are limited to Main method scope
}
int Add(int a, int b)
class Program
{
// 'a' and 'b' are limited to Add method scope
return a + b;
static void Main()
{
// 'a' and 'b' are limited to Main method scope
int a = 5, b = 3;
Console.WriteLine($"Sum: {Add(a, b)}");
}
static int Add(int a, int b)
{
// 'a' and 'b' are limited to Add method scope
return a + b;
}
}
```