Tuesday, July 15, 2025
C# note
https://github.com/markjprice/cs10dotnet6
1. naming conventions
Camel case cost, orderDetail, dateOfBirth -> Local variables, private fields
Title case aka Pascal case String, Int32, Cost -> Types, non-private fields, and other members like methods
2. double vs decimal
double is not accurate but the decimal type is accurate because it stores the number as a large integer and shifts the decimal point.
decimal c = 0.1M; // M suffix means a decimal literal value
decimal d = 0.2M;
if (c + d == 0.3M)
{
Console.WriteLine($"{c} + {d} equals {0.3M}");
}
3.
The Debug class is used to add logging that gets written only during development.
The Trace class is used to add logging that gets written during both development and runtime.
Debug.WriteLine("Debug says, I am watching!");
Trace.WriteLine("Trace says, I am watching!");
In Visual Studio, navigate to View | Output and make sure Show output from: Debug is selected.
4.
xUnit was created by the same team that built NUnit but they fixed the
mistakes they felt they made previously. xUnit is more extensible and has better community support.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment