find the current year in csharp

To find the current year in c#, you can use the DateTime.Now property to get the current date and time and then retrieve just the year component using the Year property. Here's some example code:

main.cs
int currentYear = DateTime.Now.Year;
Console.WriteLine("The current year is: " + currentYear);
95 chars
3 lines

This will output something like "The current year is: 2021" (depending on the current year when the code is executed).

gistlibby LogSnag