You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.2 KiB

  1. using System;
  2. using System.IO;
  3. public static class FSharpUsingPatterns
  4. {
  5. public static void sample1()
  6. {
  7. using (FileStream fs = File.Create("x.txt"))
  8. {
  9. fs.WriteByte((byte)1);
  10. }
  11. }
  12. public static void sample2()
  13. {
  14. Console.WriteLine("some text");
  15. using (FileStream fs = File.Create("x.txt"))
  16. {
  17. fs.WriteByte((byte)2);
  18. Console.WriteLine("some text");
  19. }
  20. }
  21. public static void sample3()
  22. {
  23. Console.WriteLine("some text");
  24. using (FileStream fs = File.Create("x.txt"))
  25. {
  26. fs.WriteByte((byte)3);
  27. }
  28. Console.WriteLine("some text");
  29. }
  30. public static void sample4()
  31. {
  32. Console.WriteLine("some text");
  33. int num;
  34. using (FileStream fs = File.OpenRead("x.txt"))
  35. {
  36. num = fs.ReadByte();
  37. }
  38. int firstByte = num;
  39. Console.WriteLine("read:" + firstByte.ToString());
  40. }
  41. public static void sample5()
  42. {
  43. Console.WriteLine("some text");
  44. int num;
  45. using (FileStream fs = File.OpenRead("x.txt"))
  46. {
  47. num = fs.ReadByte();
  48. }
  49. int firstByte = num;
  50. int num3;
  51. using (FileStream fs = File.OpenRead("x.txt"))
  52. {
  53. int num2 = fs.ReadByte();
  54. num3 = fs.ReadByte();
  55. }
  56. int secondByte = num3;
  57. Console.WriteLine("read: {0}, {1}", firstByte, secondByte);
  58. }
  59. }