SmileeTiger
Programmer
What I am trying to do is create a sorted list of users using a collection in C#. I want them to be sorted based on userID. Below is what I have so far. Any ideas on what's wrong with my add function?
using System;
using System.Collections;
namespace ChatServer
{
class UserList
{
SortedList List;
private int NumberOfUsers;
public UserList() //Constructor
{
Console.WriteLine("Created new userlist"
List= new SortedList();
}
~UserList() //Destructor
{
Console.WriteLine("Deleting the user list"
}
public int Add(User NewUser)
{
return List.Add(NewUser.UserID, (NewUser) obj); //This is totally messed. I donno what I am doing here.
}
}
class User
{
public int UserID;
//public string UserName;
private string UserName;
public string Username
{
get
{
UserInfoAccessed++;
return UserName;
}
set
{
UserName=value;
UserInfoAccessed=0;
}
}
private bool OnlineStatus;
private int UserInfoAccessed;
public User(int UserID, string UserName, bool OnlineStatus) //Constructor
{
UserInfoAccessed=0; //The number of times the user info has been accessed.
this.UserID=UserID;
this.UserName=UserName;
this.OnlineStatus=OnlineStatus;
}
~User()
{
Console.WriteLine("Deleting user {0}", this.UserID);
}
public void GetUserInfo()
{
Console.WriteLine("\n***Begin User Record***"
Console.WriteLine("User: {0}", UserID);
Console.WriteLine("User Name: {0}", UserName);
Console.WriteLine("OnlineStatus: {0}", OnlineStatus);
Console.WriteLine("*** End User Record***\n"
}
public void Logout()
{
Console.WriteLine("User {0} has now been logged out...", UserID);
OnlineStatus=false;
}
}
class ChatServer
{
static void Main(string[] args)
{
User User1= new User(1, "Cory M Hicks", true);
User1.GetUserInfo();
User1.Username="Bob";
User1.GetUserInfo();
UserList UserList1= new UserList();
//UserList1.AddUserToList(User1);
UserList1.Add(User1);
}
}
}
using System;
using System.Collections;
namespace ChatServer
{
class UserList
{
SortedList List;
private int NumberOfUsers;
public UserList() //Constructor
{
Console.WriteLine("Created new userlist"
List= new SortedList();
}
~UserList() //Destructor
{
Console.WriteLine("Deleting the user list"
}
public int Add(User NewUser)
{
return List.Add(NewUser.UserID, (NewUser) obj); //This is totally messed. I donno what I am doing here.
}
}
class User
{
public int UserID;
//public string UserName;
private string UserName;
public string Username
{
get
{
UserInfoAccessed++;
return UserName;
}
set
{
UserName=value;
UserInfoAccessed=0;
}
}
private bool OnlineStatus;
private int UserInfoAccessed;
public User(int UserID, string UserName, bool OnlineStatus) //Constructor
{
UserInfoAccessed=0; //The number of times the user info has been accessed.
this.UserID=UserID;
this.UserName=UserName;
this.OnlineStatus=OnlineStatus;
}
~User()
{
Console.WriteLine("Deleting user {0}", this.UserID);
}
public void GetUserInfo()
{
Console.WriteLine("\n***Begin User Record***"
Console.WriteLine("User: {0}", UserID);
Console.WriteLine("User Name: {0}", UserName);
Console.WriteLine("OnlineStatus: {0}", OnlineStatus);
Console.WriteLine("*** End User Record***\n"
}
public void Logout()
{
Console.WriteLine("User {0} has now been logged out...", UserID);
OnlineStatus=false;
}
}
class ChatServer
{
static void Main(string[] args)
{
User User1= new User(1, "Cory M Hicks", true);
User1.GetUserInfo();
User1.Username="Bob";
User1.GetUserInfo();
UserList UserList1= new UserList();
//UserList1.AddUserToList(User1);
UserList1.Add(User1);
}
}
}