Click here to Skip to main content
15,885,366 members
Home / Discussions / C#
   

C#

 
QuestionRe: Chart Generating Tool Pin
Richard MacCutchan26-Apr-16 23:57
mveRichard MacCutchan26-Apr-16 23:57 
AnswerRe: Chart Generating Tool Pin
gopichand.n27-Apr-16 1:56
gopichand.n27-Apr-16 1:56 
GeneralRe: Chart Generating Tool Pin
Richard MacCutchan27-Apr-16 2:09
mveRichard MacCutchan27-Apr-16 2:09 
GeneralRe: Chart Generating Tool Pin
gopichand.n3-May-16 1:39
gopichand.n3-May-16 1:39 
GeneralRe: Chart Generating Tool Pin
Richard MacCutchan3-May-16 2:34
mveRichard MacCutchan3-May-16 2:34 
QuestionC# Pin
Member 1248659326-Apr-16 7:45
Member 1248659326-Apr-16 7:45 
AnswerRe: C# Pin
OriginalGriff26-Apr-16 8:30
mveOriginalGriff26-Apr-16 8:30 
SuggestionRe: C# Pin
Sascha Lefèvre26-Apr-16 9:23
professionalSascha Lefèvre26-Apr-16 9:23 
I have a treat for you Wink | ;)
C#
public static class AgeCalculationExtension
{
    public static int CalculateCurrentAge(this DateTime birthday)
    {
        return CalculateAgeAsOf(birthday, DateTime.Today);
    }

    public static int CalculateAgeAsOf(this DateTime birthday, DateTime appointedDate)
    {
        if (appointedDate < birthday)
            throw new ArgumentOutOfRangeException(nameof(appointedDate));

        int age = appointedDate.Year - birthday.Year;
        if (birthday > appointedDate.AddYears(-age))
            age--;
        return age;
    }
}


edit: Added input validation.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson


modified 27-Apr-16 7:48am.

GeneralRe: C# Pin
Pete O'Hanlon26-Apr-16 9:31
mvePete O'Hanlon26-Apr-16 9:31 
GeneralRe: C# Pin
Matt T Heffron26-Apr-16 10:22
professionalMatt T Heffron26-Apr-16 10:22 
GeneralRe: C# Pin
Pete O'Hanlon26-Apr-16 10:58
mvePete O'Hanlon26-Apr-16 10:58 
GeneralRe: C# Pin
Sascha Lefèvre26-Apr-16 12:01
professionalSascha Lefèvre26-Apr-16 12:01 
SuggestionRe: C# Pin
Richard Deeming27-Apr-16 1:47
mveRichard Deeming27-Apr-16 1:47 
GeneralRe: C# Pin
Sascha Lefèvre27-Apr-16 1:49
professionalSascha Lefèvre27-Apr-16 1:49 
QuestionCapture exceptions and handle those in my custom error handler Pin
Member 1204569226-Apr-16 5:37
Member 1204569226-Apr-16 5:37 
AnswerRe: Capture exceptions and handle those in my custom error handler Pin
Eddy Vluggen26-Apr-16 5:48
professionalEddy Vluggen26-Apr-16 5:48 
QuestionStudent admin management system C# console Pin
Member 1248538426-Apr-16 5:19
Member 1248538426-Apr-16 5:19 
QuestionRe: Student admin management system C# console Pin
Richard MacCutchan26-Apr-16 5:26
mveRichard MacCutchan26-Apr-16 5:26 
AnswerRe: Student admin management system C# console Pin
Eddy Vluggen26-Apr-16 5:55
professionalEddy Vluggen26-Apr-16 5:55 
GeneralRe: Student admin management system C# console Pin
Member 1248538426-Apr-16 7:48
Member 1248538426-Apr-16 7:48 
QuestionRe: Student admin management system C# console Pin
Eddy Vluggen26-Apr-16 8:25
professionalEddy Vluggen26-Apr-16 8:25 
GeneralRe: Student admin management system C# console Pin
Matt T Heffron26-Apr-16 7:54
professionalMatt T Heffron26-Apr-16 7:54 
AnswerRe: Student admin management system C# console Pin
Member 1507847221-Feb-21 3:00
Member 1507847221-Feb-21 3:00 
AnswerRe: Student admin management system C# console Pin
Member 1507847221-Feb-21 3:12
Member 1507847221-Feb-21 3:12 
AnswerRe: Student admin management system C# console Pin
Member 1563833516-May-22 9:50
Member 1563833516-May-22 9:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.