2016-08-15 20 views
-1

了StyleCop警告SA1201我已經修改下課後如下了StyleCop發出SA1201:項目在Order類

/// <summary> 
/// Class Data 
/// </summary> 
public class DataClass 
{ 
    /// <summary> 
    /// Gets or sets Id 
    /// </summary> 
    public string Id 
    { 
     get { return this.id; } 
     set { this.id = value; } 
    } 

    /// <summary> 
    /// Gets or sets Name 
    /// </summary> 
    public string Name 
    { 
     get { return this.name; } 
     set { this.name = value; } 
    } 

    /// <summary> 
    /// Declare variable name 
    /// </summary> 
    private string name; 

    /// <summary> 
    /// Declare variable id 
    /// </summary> 
    private string id; 
} 

還是一樣的錯誤顯示 「所有屬性必須放在所有字段後」

+0

你明白了倒退。 'id'和'name'前的'id'和'name'。 – juharr

回答

2

我認爲你在混合屬性和字段。屬性使用getter和setter,而字段是「傳統」變量。

https://msdn.microsoft.com/library/x9fsa0sw.aspx

你的代碼應該是這樣的:

/// <summary> 
/// Class Data 
/// </summary> 
public class DataClass 
{  
    /// <summary> 
    /// Declare variable name 
    /// </summary> 
    private string name; 

    /// <summary> 
    /// Declare variable id 
    /// </summary> 
    private string id; 

    /// <summary> 
    /// Gets or sets Id 
    /// </summary> 
    public string Id 
    { 
     get { return this.id; } 
     set { this.id = value; } 
    } 

    /// <summary> 
    /// Gets or sets Name 
    /// </summary> 
    public string Name 
    { 
     get { return this.name; } 
     set { this.name = value; } 
    } 
} 
相關問題