Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.IO;
- using System.Runtime.Serialization.Formatters.Binary;
- using System.Threading;
- using System.Windows.Forms;
- namespace Traning
- {
- [Serializable]
- class MyArr : IEnumerable
- {
- private int[] arr;
- public int Size{ get => arr.Length;}
- public MyArr(int size = 0) { arr = new int[size]; }
- public MyArr(int[] _arr) => arr = _arr;
- public MyArr FullRandomNumres()
- {
- var rnd = new Random();
- for (int i = 0; i < arr.Length; ++i) arr[i] = rnd.Next(-100, 100);
- return this;
- }
- public MyArr Print()
- {
- foreach (var n in arr) Console.Write($"{n} ");
- return this;
- }
- public static void SaveToFile(string filename, MyArr value)
- {
- using (var fs = new FileStream(filename, FileMode.OpenOrCreate))
- {
- new BinaryFormatter().Serialize(fs,value);
- }
- }
- public static MyArr LoadFromFile(string filename)
- {
- using (var fs = File.OpenRead(filename))
- {
- return new MyArr( new BinaryFormatter().Deserialize(fs) as int []);
- }
- }
- public int this[int index] { get => arr[index]; set => arr[index] = value;}
- public IEnumerator GetEnumerator() => arr.GetEnumerator();
- }
- public delegate int DisplayHandler();
- public delegate DialogResult show(string x);
- class Program
- {
- static void Main(string[] args)
- {
- /*var arr = new MyArr(10);
- arr.FullRandomNumres().Print();
- Console.WriteLine();
- var filename = @"c:\input";
- MyArr.SaveToFile(filename, arr);
- arr = MyArr.LoadFromFile(filename);
- arr.Print();*/
- DisplayHandler handler = new DisplayHandler(Display);
- var s = new show((x) => MessageBox.Show(x));
- IAsyncResult resultObj = handler.BeginInvoke(null, null);
- var rs = s.BeginInvoke("Hello",null, null);
- Thread.Sleep(1000);
- Console.WriteLine("Продолжается работа метода Main");
- int result = handler.EndInvoke(resultObj);
- Console.WriteLine("Результат равен {0}", result);
- }
- static int Display()
- {
- Console.WriteLine("Начинается работа метода Display...");
- int result = 0;
- for (int i = 1; i < 10; i++)
- {
- result += i * i;
- }
- Thread.Sleep(3000);
- Console.WriteLine("Завершается работа метода Display....");
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement