Bạn có thể cho tôi biết cách sử dụng chính xác của tài sản trong C# tôi có nghĩa là lời giải thích thực tếTại sao chúng ta cần Properties trong C#
trong dự án của chúng tôi, chúng tôi đang sử dụng tài sản như
/// <summary>
/// column order
/// </summary>
protected int m_order;
/// <summary>
/// Get/Set column order
/// </summary>
public int Order
{
get { return m_order; }
set { m_order = value; }
}
/// <summary>
/// constructor
/// </summary>
/// <param name="name">column name</param>
/// <param name="width">column width</param>
/// <param name="order">column order</param>
public ViewColumn(string name, int width, int order)
{
//
// TODO: Add constructor logic here
//
m_name = name;
m_width = width;
m_order = order;
}
/// <summary>
/// returns the column name, width, and order in list view.
/// </summary>
/// <returns>string represent of the ViewColumn object</returns>
public override string ToString()
{
return (string.Format("column name = {0}, width = {1}, order = {2}.",
m_name, m_width, m_order));
}
/// <summary>
/// Do a comparison of 2 ViewColumn object to see if they're identical.
/// </summary>
/// <param name="vc">ViewColumn object for comparison</param>
/// <returns>True if the objects are identical, False otherwise.</returns>
public override bool Equals(object obj)
{
ViewColumn vc = (ViewColumn)obj;
if(m_name == vc.Name &&
m_width == vc.Width &&
m_order == vc.Order)
return true;
else
return false;
}
của [Tôi có nên sử dụng các thuộc tính công khai và các trường riêng tư hoặc các trường công khai cho dữ liệu không?] (http://stackoverflow.com/questions/1277572/should-i-use-public-properties-and-private-fields-or-public- các trường dữ liệu) – nawfal