Advertisement
lightxx

Untitled

Feb 8th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.72 KB | None | 0 0
  1. using System;
  2. using System.Net;
  3.  
  4. namespace FunWithClasses {
  5.     class Program {
  6.         static void Main() {
  7.  
  8.             // lets say we receive an array of strings from the socket or whatever
  9.             string[] thisIsWhatIGot = new[] {"Maxi's Game", "10.10.1.1", "9999", "4", "4", "5"};
  10.  
  11.             // parse the input parameters to their appropriate data types
  12.  
  13.             // this is the name of the game
  14.             string gamename = thisIsWhatIGot[0];
  15.  
  16.             // Create an IP Address from the input array
  17.             IPAddress ipAddress = IPAddress.Parse(thisIsWhatIGot[1]);
  18.  
  19.             // the port
  20.             Int16 port = Int16.Parse(thisIsWhatIGot[2]);
  21.  
  22.             // breiter hoeher tiefer schneller
  23.             Byte breite = Byte.Parse(thisIsWhatIGot[3]);
  24.             Byte hoehe = Byte.Parse(thisIsWhatIGot[4]);
  25.             Byte tiefe = Byte.Parse(thisIsWhatIGot[5]);
  26.  
  27.             // ok. convert the string into a strong typed object
  28.  
  29.             GameInfo gameInfo = new GameInfo(gamename, ipAddress, port, breite, hoehe, tiefe);
  30.  
  31.             // ok. that's it.
  32.  
  33.             Console.WriteLine("The IP is: " + gameInfo.IpAddress);
  34.  
  35.             Console.WriteLine("The name of the game is: " + gameInfo.Spielname);
  36.  
  37.             Console.ReadLine();
  38.         }
  39.     }
  40.     public class GameInfo {
  41.         // some PRIVATE members.
  42.         private string _spielname;
  43.         private IPAddress _ipAddress;
  44.         private Int16 _port;
  45.         private byte _breite;
  46.         private byte _hoehe;
  47.         private byte _tiefe;
  48.  
  49.         // default constructor
  50.         public GameInfo() {
  51.            
  52.         }
  53.  
  54.         // constructor taking arguments
  55.         public GameInfo(string spielname, IPAddress ipAddress, Int16 port,
  56.             byte breite, byte hoehe, byte tiefe) {
  57.             _spielname = spielname;
  58.             IpAddress = ipAddress;
  59.             Port = port;
  60.             Breite = breite;
  61.             Hoehe = hoehe;
  62.             Tiefe = tiefe;
  63.         }
  64.         // the properties
  65.         public string Spielname {
  66.             get { return _spielname; }
  67.             set { _spielname = value; }
  68.         }
  69.  
  70.         public IPAddress IpAddress {
  71.             get { return _ipAddress; }
  72.             set { _ipAddress = value; }
  73.         }
  74.  
  75.         public short Port {
  76.             get { return _port; }
  77.             set { _port = value; }
  78.         }
  79.  
  80.         public byte Breite {
  81.             get { return _breite; }
  82.             set { _breite = value; }
  83.         }
  84.  
  85.         public byte Hoehe {
  86.             get { return _hoehe; }
  87.             set { _hoehe = value; }
  88.         }
  89.  
  90.         public byte Tiefe {
  91.             get { return _tiefe; }
  92.             set { _tiefe = value; }
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement