This code demonstrates several important C# features introduced in C# 3.0 and later versions. Let's explore each concept in detail.
Partial classes allow you to split the definition of a class across multiple source files. This is particularly useful for:
partial
keyword// File: MathsOperations.cs
public partial class Maths
{
public int Add(int a, int b)
{
return a + b;
}
}
// File: MathsAdvanced.cs
public partial class Maths
{
public int Sub(int a, int b)
{
return a - b;
}
}
The var
keyword enables implicit type declaration where the compiler infers the type from the right-hand side of the assignment. This feature provides: