Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Stylecop发布SA1201:类中项的顺序_C#_Asp.net_Stylecop - Fatal编程技术网

C# Stylecop发布SA1201:类中项的顺序

C# Stylecop发布SA1201:类中项的顺序,c#,asp.net,stylecop,C#,Asp.net,Stylecop,在Stylecop警告SA1201之后,我对类进行了如下修改 /// <summary> /// Class Data /// </summary> public class DataClass { /// <summary> /// Gets or sets Id /// </summary> public string Id { get { return this.id; }

在Stylecop警告SA1201之后,我对类进行了如下修改

/// <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;
}
//
///类数据
/// 
公共类数据类
{
/// 
///获取或设置Id
/// 
公共字符串Id
{
获取{返回this.id;}
设置{this.id=value;}
}
/// 
///获取或设置名称
/// 
公共字符串名
{
获取{返回this.name;}
设置{this.name=value;}
}
/// 
///声明变量名
/// 
私有字符串名称;
/// 
///声明变量id
/// 
私有字符串id;
}
仍然显示相同的错误
“所有属性必须放在所有字段之后”

我认为您将属性和字段混为一谈。属性使用getter和setter,而字段是“传统”变量

您的代码应该如下所示:

/// <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; }
    }
}
//
///类数据
/// 
公共类数据类
{    
/// 
///声明变量名
/// 
私有字符串名称;
/// 
///声明变量id
/// 
私有字符串id;
/// 
///获取或设置Id
/// 
公共字符串Id
{
获取{返回this.id;}
设置{this.id=value;}
}
/// 
///获取或设置名称
/// 
公共字符串名
{
获取{返回this.name;}
设置{this.name=value;}
}
}

你已经把它倒过来了<在
id
name
之前的code>id和
name