Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Labrat
- {
- class Lab03
- {
- public class Assari1
- {
- //Properties
- public string Syote { get; set; }
- public string Pvm { get; set; }
- //Constructors
- public Assari1(string Syote, string Pvm)
- {
- this.Syote = Syote;
- this.Pvm = Pvm;
- }
- public Assari1()
- {
- }
- //Methods
- public static bool OnkoLuku(string Syote)
- {
- Console.WriteLine("Syötä luku (kokonaisluku tai desimaaliluku erottimena pilkku, pistettä ei hyväksytä)");
- Syote = Console.ReadLine();
- double number;
- bool result = double.TryParse(Syote, out number);
- if (result == true)
- {
- Console.WriteLine("True " + number);
- return true;
- }
- else
- {
- Console.WriteLine("False");
- return false;
- }
- }
- public static bool OnkoPvm(string Pvm)
- {
- var dateFormats = new[] { "dd.MM.yyyy", "dd.MM.yy" };
- Console.WriteLine("Syötä päivämäärä muodossa pp.kk.vvvv tai pp.kk.vv");
- Pvm = Console.ReadLine();
- DateTime scheduleDate;
- bool validDate = DateTime.TryParseExact(Pvm, dateFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out scheduleDate);
- if (validDate)
- {
- Console.WriteLine("Sehän passaa " + scheduleDate.ToShortDateString());
- return true;
- }
- else
- {
- Console.WriteLine("Ee passaa " + Pvm);
- return false;
- }
- }
- }
- public class TestiPeti
- {
- public static void TestaaTehtava()
- {
- Assari1 assari = new Assari1();
- Assari1.OnkoLuku(assari.Syote);
- Assari1.OnkoPvm(assari.Pvm);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement