日期:2014-05-18  浏览次数:20466 次

请问如何定义这样的类?
定义后我可以这样来用它:
protected ArrayList result = null;
MyClass mc = new MyClass();
result = mc.return_array();

string my0_1 = result[0].m_aaa;
string my0_2 = result[0].m_bbb;
int my0_3 = result[0].m_ccc;

string my1_1 = result[1].m_aaa;
string my1_2 = result[1].m_bbb;
int my1_3 = result[1].m_ccc;

......

可见,该类返回的result是一个数组,而每个数组元素有包含多个属性。
类的属性如m_aaa,m_bbb,m_ccc可以在定义类是先分别赋好值。
本人对定义类不太熟,请高人指教,谢谢!

------解决方案--------------------
C# code

//实体类,users.cs
namespace OwnerUsers
{
  public class Users
  {
    public Users(){}

    private int _id;
    private string _username;
    private string _password;
    
    public int ID
    {
      get{return _id;}
      set{_id = value;}
    }
    public string Userame
    {
      get{return _username;}
      set{_username= value;}
    }
    public string Password
    {
      get{return _password;}
      set{_password= value;}
    }

  }
}

//Test
namespace OwnerUsers
{
  pulic class Test
  {
    public static void Main(string[] args)
    {
      List<Users> list = new List<Users>();
      for(int i=0; i<5; i++)
      {
        Users user = new Users();
        user.ID = 1;
        user.Username = "U"+i.ToString();
        user.Password = "P"+i.Tostring();
        list.Add(user);
      }
      foreach(Users u in list)
      {
        Console.WriteLine("{},{1},{2}",u.ID,u.Username,u.Password);
      }
    }
  }
}