Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.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# 排序的动态列表是否为只读?_C#_Asp.net_Linq - Fatal编程技术网

C# 排序的动态列表是否为只读?

C# 排序的动态列表是否为只读?,c#,asp.net,linq,C#,Asp.net,Linq,我有一个动态列表,我尝试对其进行排序,然后根据新的排序顺序更改id: foreach (Case c in cases) { bool edit = true; if (c.IsLocked.HasValue) edit = !c.IsLocked.Value; eventList.Add(new { id = row.ToString(), realid = "c" + c.CaseID.ToString(),

我有一个动态列表,我尝试对其进行排序,然后根据新的排序顺序更改id:

foreach (Case c in cases)
{
    bool edit = true;

    if (c.IsLocked.HasValue)
        edit = !c.IsLocked.Value;

    eventList.Add(new {
        id = row.ToString(),
        realid = "c" + c.CaseID.ToString(),
        title = c.CaseTitle + "-" + c.Customer.CustomerDescription,
        start = ResolveStartDate(StartDate(c.Schedule.DateFrom.Value.AddSeconds(row))),
        end = ResolveEndDate(StartDate(c.Schedule.DateFrom.Value), c.Schedule.Hours.Value),
        description = c.CaseDescription,
        allDay = false,
        resource = c.Schedule.EmployeID.ToString(),
        editable = edit,
        color = ColorConversion.HexConverter(System.Drawing.Color.FromArgb(c.Color.Value))
    });

    row++;

}

var sortedList = eventList.OrderBy(p => p.title);

for (int i = 0; i < sortedList.Count(); ++i)
{
    sortedList.ElementAt(i).id = i.ToString();
}
foreach(案例中的案例c)
{
bool edit=true;
如果(c.IsLocked.HasValue)
编辑=!c.IsLocked.Value;
事件列表。添加(新){
id=行。ToString(),
realid=“c”+c.CaseID.ToString(),
title=c.casettitle+“-”+c.Customer.CustomerDescription,
start=ResolveStartDate(StartDate(c.Schedule.DateFrom.Value.AddSeconds(行)),
end=ResolveEndDate(StartDate(c.Schedule.DateFrom.Value)、c.Schedule.Hours.Value),
描述=c.案例描述,
全天=假,
resource=c.Schedule.EmployeID.ToString(),
可编辑=编辑,
color=ColorConversion.HexConverter(System.Drawing.color.FromArgb(c.color.Value))
});
行++;
}
var sortedList=eventList.OrderBy(p=>p.title);
对于(int i=0;i
但是它在
sortedList.ElementAt(i.id=i.ToString()上崩溃声明它是只读的

无法将属性或索引器
f\uu AnonymousType4.id
分配给--它是只读的

如何更改ID


谢谢

如上所述,您无法更新匿名类型,但是您可以修改流程,使用一个查询,首先对项目进行排序,并将项目索引作为参数包含在
选择中:

var query = cases.OrderBy(c => c.CaseTitle + "-" + c.Customer.CustomerDescription)
                 .Select( (c, i) =>
                    new {
                            id = i.ToString(),
                            realid = "c" + c.CaseID.ToString(),
                            title = c.CaseTitle + "-" + c.Customer.CustomerDescription,
                            start = ResolveStartDate(StartDate(c.Schedule.DateFrom.Value.AddSeconds(i))),
                            end = ResolveEndDate(StartDate(c.Schedule.DateFrom.Value), c.Schedule.Hours.Value),
                            description = c.CaseDescription,
                            allDay = false,
                            resource = c.Schedule.EmployeID.ToString(),
                            editable = c.IsLocked.HasValue ? !c.IsLocked.Value : true ,
                            color = ColorConversion.HexConverter(System.Drawing.Color.FromArgb(c.Color.Value))
                        }
                   );

您可以尝试将排序后的列表复制到新的列表实例什么类型是
.id
?如果这是一个只有get访问器的属性,您不能设置它。+1您发布了我刚刚准备发布的确切解决方案。当我看到一个新的答案被贴出来时,我已经把它写好了