Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,690 questions

55,449 answers

573 users

How to check all years in array of years if they are leap years or not in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        int[] array = { 2023, 2022, 2021, 2020, 2019, 2018, 2017, 2016, 1900, 1800, 1700, 1600 };

        foreach (int year in array) {
            if (DateTime.IsLeapYear(year)) {
                Console.WriteLine($"{year} is a leap year");
            } else {
                Console.WriteLine($"{year} is NOT a leap year");
            }
        }
    }
}




/*
run:

2023 is NOT a leap year
2022 is NOT a leap year
2021 is NOT a leap year
2020 is a leap year
2019 is NOT a leap year
2018 is NOT a leap year
2017 is NOT a leap year
2016 is a leap year
1900 is NOT a leap year
1800 is NOT a leap year
1700 is NOT a leap year
1600 is a leap year

*/

 



answered Jul 8, 2023 by avibootz

Related questions

1 answer 152 views
1 answer 143 views
143 views asked Oct 18, 2024 by avibootz
2 answers 213 views
213 views asked Feb 13, 2021 by avibootz
2 answers 290 views
290 views asked Feb 13, 2021 by avibootz
...