Lately I've been busy learning Visual C# 2005 programming. I like C#, its easy to create desktop applications using the visual designer and hardening the application by good coding practice. Since I am new to C# I find it very interesting. Just recently I was able to add code that would calculate a person's age automatically. This is an easy thing to do for experts though. This was what I made:
public void CalculateAge(object sender, EventArgs e)
{
DateTime birthdate = Convert.ToDateTime(txtBirthdate.text);
DateTime now = DateTime.Today;
int year = now.year - birthdate.year;
int month = now.month - birthdate.month;
int day = now.day - birthdate.day;
if (month < 0)
{
int year = year - 1;
int month = now.month;
int day = now.day - birthday.day;
}
if (day < 0)
{
int month = month - 1;
int day = now.day;
}
txtAge.text = year + "Y " + month + "M " + day + "D";
}
Learning small stuff like this is like building blocks of cement to a building. You start small and then eventually creating something big.
That would be it for now.
Friday, July 13, 2007
Trying out Visual C# 2005
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment