Advertisement
sokolova4

H

Jan 9th, 2021
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Server
  5. {
  6.     private static string name;
  7.  
  8.     public Server()
  9.     {
  10.     }
  11.     public Server(string x)
  12.     {
  13.         name = x;
  14.     }
  15.     static string ans = "";
  16.     public static Server Connect(string Name)
  17.     {
  18.         if (name is null) return new Server(Name);
  19.         else return new Server(name);
  20.     }
  21.  
  22.     public void Send(string message)
  23.     {
  24.         if(name is null)
  25.         {
  26.             throw new ArgumentException("No connected server");
  27.         }
  28.        
  29.         ans += $"Sending data {message} to server {name }";
  30.         ans += Environment.NewLine;
  31.     }
  32.  
  33.     public void Receive(string message)
  34.     {
  35.         if (name is null)
  36.         {
  37.             throw new ArgumentException("No connected server");
  38.         }
  39.        
  40.         ans += $"Receiving data {message} from server {name}";
  41.         ans += Environment.NewLine;
  42.     }
  43.  
  44.     public void Output()
  45.     {
  46.         if (name is null)
  47.         {
  48.             throw new ArgumentException("No connected server");
  49.         }
  50.         Console.Write(ans);
  51.         ans = "";
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement