Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Labrat
  9. {
  10. class Lab03
  11. {
  12. public class Assari1
  13. {
  14. //Properties
  15. public string Syote { get; set; }
  16. public string Pvm { get; set; }
  17. //Constructors
  18. public Assari1(string Syote, string Pvm)
  19. {
  20. this.Syote = Syote;
  21. this.Pvm = Pvm;
  22. }
  23. public Assari1()
  24. {
  25. }
  26.  
  27. //Methods
  28. public static bool OnkoLuku(string Syote)
  29. {
  30. Console.WriteLine("Syötä luku (kokonaisluku tai desimaaliluku erottimena pilkku, pistettä ei hyväksytä)");
  31. Syote = Console.ReadLine();
  32. double number;
  33. bool result = double.TryParse(Syote, out number);
  34. if (result == true)
  35. {
  36. Console.WriteLine("True " + number);
  37. return true;
  38. }
  39. else
  40. {
  41. Console.WriteLine("False");
  42. return false;
  43. }
  44. }
  45. public static bool OnkoPvm(string Pvm)
  46. {
  47. var dateFormats = new[] { "dd.MM.yyyy", "dd.MM.yy" };
  48. Console.WriteLine("Syötä päivämäärä muodossa pp.kk.vvvv tai pp.kk.vv");
  49. Pvm = Console.ReadLine();
  50. DateTime scheduleDate;
  51. bool validDate = DateTime.TryParseExact(Pvm, dateFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out scheduleDate);
  52. if (validDate)
  53. {
  54. Console.WriteLine("Sehän passaa " + scheduleDate.ToShortDateString());
  55. return true;
  56. }
  57. else
  58. {
  59. Console.WriteLine("Ee passaa " + Pvm);
  60. return false;
  61. }
  62. }
  63. }
  64. public class TestiPeti
  65. {
  66. public static void TestaaTehtava()
  67. {
  68. Assari1 assari = new Assari1();
  69. Assari1.OnkoLuku(assari.Syote);
  70. Assari1.OnkoPvm(assari.Pvm);
  71. }
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement