Akis Forum

Welcome to AkisForum.com! Register your free account today and become a member! Once signed in, you'll be able to dive into learning to code, discovering new tools, and keeping up with the latest trends. AkisForum is where benefit, knowledge, and sharing come together. Join us to add your own topics and posts, and connect with other members through your private inbox!

📅 [C#] Konsol Tabanlı Basit Takvim Gösterici

sefack

Member
Akisor
Açıklama:
🗓️ Kullanıcının yıl ve ay girmesiyle o ayın takvimini konsolda gösteren basit C# konsol uygulaması. System.Globalization kullanarak ayın günlerini ve haftanın günlerini listeler.

Kodlar:

Program.cs
C#:
using System;
using System.Globalization;

namespace BasitTakvim
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Takvim Gösterici");
            
            int yil = 0;
            int ay = 0;

            while (true)
            {
                Console.Write("Yıl girin (örn: 2025): ");
                if (int.TryParse(Console.ReadLine(), out yil) && yil > 0)
                    break;
                Console.WriteLine("Geçerli bir yıl girin.");
            }

            while (true)
            {
                Console.Write("Ay girin (1-12): ");
                if (int.TryParse(Console.ReadLine(), out ay) && ay >= 1 && ay <= 12)
                    break;
                Console.WriteLine("Geçerli bir ay girin.");
            }

            DateTime ilkGun = new DateTime(yil, ay, 1);
            int gunSayisi = DateTime.DaysInMonth(yil, ay);

            Console.WriteLine($"\n{CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(ay)} {yil} Takvimi");
            Console.WriteLine("Pzt Sal Çar Per Cum Cmt Paz");

            int baslangicGunu = (int)ilkGun.DayOfWeek;
            if (baslangicGunu == 0) // Pazar ise 6 yap (hafta başı Pazartesi)
                baslangicGunu = 6;
            else
                baslangicGunu -= 1;

            for (int i = 0; i < baslangicGunu; i++)
                Console.Write(" ");

            for (int gun = 1; gun <= gunSayisi; gun++)
            {
                Console.Write($"{gun,3} ");

                if ((gun + baslangicGunu) % 7 == 0)
                    Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
}

 
Geri
Üst