Exemplo n.º 1
0
 private void btnAgeService_Click(object sender, EventArgs e)
 {
     var client = new AgeServiceClient();
     DateTime birthDate;
     if (DateTime.TryParse(txtAgeService.Text, out birthDate))
     {
         var result = client.CalculateAge(birthDate);
         lblResult.Text =
             $"Du är {result.DaysOld} dagar gammal, {result.HoursOld} timmar gammal och {result.MinutesOld} minuter gammal";
     }
     else
         lblResult.Text = txtAgeService.Text + " funkar inte som en datum";
 }
Exemplo n.º 2
0
        private static void DoAgeServicePart()
        {
            var client = new AgeServiceClient();
            DateTime answerDate;

            do
            {
                Console.Write("Skriv ditt födelseår (Format exempel: 1980-11-02):");
            }
            while (!DateTime.TryParse(Console.ReadLine(), out answerDate));
            
            var result = client.CalculateAge(answerDate);
            Console.WriteLine($"Du är:\r\n" +
                              $"{result.DaysOld} dagar gammal\r\n" +
                              $"{result.HoursOld} timmar gammal\r\n" +
                              $"{result.MinutesOld} minuter gammal\r\n");
        }