Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net;
- namespace FunWithClasses {
- class Program {
- static void Main() {
- // lets say we receive an array of strings from the socket or whatever
- string[] thisIsWhatIGot = new[] {"Maxi's Game", "10.10.1.1", "9999", "4", "4", "5"};
- // parse the input parameters to their appropriate data types
- // this is the name of the game
- string gamename = thisIsWhatIGot[0];
- // Create an IP Address from the input array
- IPAddress ipAddress = IPAddress.Parse(thisIsWhatIGot[1]);
- // the port
- Int16 port = Int16.Parse(thisIsWhatIGot[2]);
- // breiter hoeher tiefer schneller
- Byte breite = Byte.Parse(thisIsWhatIGot[3]);
- Byte hoehe = Byte.Parse(thisIsWhatIGot[4]);
- Byte tiefe = Byte.Parse(thisIsWhatIGot[5]);
- // ok. convert the string into a strong typed object
- GameInfo gameInfo = new GameInfo(gamename, ipAddress, port, breite, hoehe, tiefe);
- // ok. that's it.
- Console.WriteLine("The IP is: " + gameInfo.IpAddress);
- Console.WriteLine("The name of the game is: " + gameInfo.Spielname);
- Console.ReadLine();
- }
- }
- public class GameInfo {
- // some PRIVATE members.
- private string _spielname;
- private IPAddress _ipAddress;
- private Int16 _port;
- private byte _breite;
- private byte _hoehe;
- private byte _tiefe;
- // default constructor
- public GameInfo() {
- }
- // constructor taking arguments
- public GameInfo(string spielname, IPAddress ipAddress, Int16 port,
- byte breite, byte hoehe, byte tiefe) {
- _spielname = spielname;
- IpAddress = ipAddress;
- Port = port;
- Breite = breite;
- Hoehe = hoehe;
- Tiefe = tiefe;
- }
- // the properties
- public string Spielname {
- get { return _spielname; }
- set { _spielname = value; }
- }
- public IPAddress IpAddress {
- get { return _ipAddress; }
- set { _ipAddress = value; }
- }
- public short Port {
- get { return _port; }
- set { _port = value; }
- }
- public byte Breite {
- get { return _breite; }
- set { _breite = value; }
- }
- public byte Hoehe {
- get { return _hoehe; }
- set { _hoehe = value; }
- }
- public byte Tiefe {
- get { return _tiefe; }
- set { _tiefe = value; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement