Đây là một bài tập đơn giản khi ta bắt đầu làm quen với kiểu dữ liệu date(ngày) trong ngôn ngữ lâp trình C#, bài tập yêu cầu bạn so sánh hai ngày cho trước và in ra ngày nào xảy ra trước và ngày nào xảy ra sau.
C-Sharp Example Source Code:
C-Sharp Example Source Code:
--------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharpExample
{
class CompareTwoDates
{
static void Main(string[] args)
{
DateTime sd = new DateTime(2010, 10, 12);
Console.WriteLine("Starting Date : {0}", sd);
DateTime ed = sd.AddDays(10);
Console.WriteLine("Ending Date : {0}", ed);
if (sd < ed)
{
Console.WriteLine("{0} Occurs Before {1}", sd, ed);
}
Console.Read();
}
}
}
---------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharpExample
{
class CompareTwoDates
{
static void Main(string[] args)
{
DateTime sd = new DateTime(2010, 10, 12);
Console.WriteLine("Starting Date : {0}", sd);
DateTime ed = sd.AddDays(10);
Console.WriteLine("Ending Date : {0}", ed);
if (sd < ed)
{
Console.WriteLine("{0} Occurs Before {1}", sd, ed);
}
Console.Read();
}
}
}
---------------------
No comments:
Post a Comment