Thread: c# array

  1. #1
    Registered User
    Join Date
    Mar 2009

    c# array

    I am building a telnet server and I want to no how to make an array. This array needs to include a socket, streamreader, streamwriter, and the ipaddress, is this possible?

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    RING 0
    Make a class with the information you needed and then add it to a list. Otherwise to make a new array of your class it would be something like:

    yourClass[] Something = new yourClass[SIZE]();

  3. #3
    Join Date
    Dec 2007
    Might I suggest you learn the basics of the C# language before you try to write a server?

  4. #4
    Registered User
    Join Date
    Mar 2009
    Rags is correct. You need to have at least a basic understanding of OOP.

    From the criteria you've listed, I would make an object such as:

    class UserObject
        public Socket socket;
        public IPAddress ip;
        public StreamReader reader;
        public StreamWriter writer;
        public UserObject() { }
        public UserObject(Socket socket)
            this.socket = socket;
            this.ip = ((IPEndPoint)socket.RemoteEndPoint).Address;
            this.reader = new StreamReader(new NetworkStream(socket));
            this.writer = new StreamWriter(new NetworkStream(socket));
    Once you've created an object you're happy with, you could either use an ArrayList, or even better would be a List<T> since all the array elements will be the same object type:

    List<UserObject> my_users = new List<UserObject>();

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  2. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM