0

我正在尝试使用以下代码执行此操作,但它给了我很多错误:

public abstract class BaseGridViewModel
{

    protected BaseGridViewModel()
    {
        Events = new List<ViewEvent>();
        Watch = Stopwatch.StartNew();
    }
    public SelectList Statuses { get; set; }
    public IList<ViewEvent> Events { get; set; }
    public string Topics { get; set; }
    public SelectList Types { get; set; }
    public string View { get; set; }
    public Stopwatch Watch { get; set; }

    public void Event(string description) {
        if (Watch.IsRunning) {
            Events.Add(new ViewEvent(description, Watch.ElapsedMilliseconds));
        } else {
            throw new Exception("Watch not running");
        }
    }
    public long Elapsed {
        get { 
            return Events.Sum(event => event.Elapsed)
        }
    }

public class ViewEvent {

    public long Elapsed { get; private set; }
    public string Description { get; private set; }
    public string Message { get; private set; }
    public int Quantity { get; private set; }

    public ViewEvent(string description, long elapsedTime, int quantity = 0, string message = "") {
        this.Description = description; 
        this.Elapsed = elapsedTime;
        this.Quantity = quantity;
        this.Message = message;
    }

}

所有 9 个错误都针对这一行:“return Events.Sum(event => event.Elapsed)”

我的语法有问题吗?

4

1 回答 1

2

event是关键字,试试e => e.Elapsed

于 2012-09-14T08:09:56.257 回答