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

this.userName = userName;这到底是什么意思啊!!
namespace Model
{
  /// <summary>
  /// Admin类
  /// </summary>
  [Serializable]
  public class Admin
  {

  #region fields
  private string userName;
  private string userPass;
  #endregion

  #region properties
  ///<summary>
  ///管理员账号
  ///</summary>
  public string UserName//声明了UserName参数并对其属性予以赋值
  {
  get { return userName; }
  set { userName = value; }
  }
  ///<summary>
  ///管理员密码
  ///</summary>
  public string UserPass
  {
  get { return userPass; }
  set { userPass = value; }
  }

  #endregion

  ///<summary>
  ///constructor
  ///</summary>
  public Admin(string userName, string userPass)//定义了Admin的方法
  {
  this.userName = userName;
  this.userPass = userPass;
  }

  public Admin()
  {

  }
  }

}
源码如上,请问下 this.userName = userName;这到底是什么意思啊!!有什么意义呢?

------解决方案--------------------
public Admin(string userName, string userPass)// userName是参数
{
this.userName = userName;//this.userName 这里userName 是类的成员变量 this是为了区分这两个userName
this.userPass = userPass;
}
这么写你对比写就理解了
public Admin(string uName, string uPass
{
this.userName = uName;//或userName = uName
this.userPass = uPass;//userPass = uPass
}

------解决方案--------------------
探讨