Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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# “奇数”;使用可能未指定的字段';类型'"E;”CS0170_C#_C# 4.0 - Fatal编程技术网

C# “奇数”;使用可能未指定的字段';类型'"E;”CS0170

C# “奇数”;使用可能未指定的字段';类型'"E;”CS0170,c#,c#-4.0,C#,C# 4.0,我可能遗漏了一些东西,但我得到了一个我认为奇怪的错误,其他开发人员都没有得到相同的代码 public void SomeMethod(... symbolInfo) { ElementId elementId = symbolInfo.GetElementIds().Head(true); if (elementId.HasValue()) { // error here "Use of possibly unassigned field 'Type'"

我可能遗漏了一些东西,但我得到了一个我认为奇怪的错误,其他开发人员都没有得到相同的代码

public void SomeMethod(... symbolInfo)
{
   ElementId elementId = symbolInfo.GetElementIds().Head(true);
   if (elementId.HasValue())
   {
      // error here "Use of possibly unassigned field 'Type'"
      object element = repository.FindElement(elementId.Type, elementId.Id);
      if (element != null) { ... }
   }
}

public struct ElementId
{
   public string Id;
   public MDAPI_ElementType Type;
}
使用以下扩展方法:

public static bool IsEmpty(this ElementId id)
{
    return id.Type == ElementType.ElementUnknown || string.IsNullOrEmpty(id.Id);
}

public static bool HasValue(this ElementId id)
{
   return !id.IsEmpty();
}

有人能告诉我为什么不能生成吗?

我已经设法修复了生成错误,而是调用了一个直接获取ElementId的扩展方法。我不知道为什么这会解决这个问题

public static object FindElement(this IMRepository rep, ElementId element)
{
    return rep.FindElement(element.Type, element.Id);
}

symbolInfo.getElementId().Head(true)
如何创建
ElementId
?@ChrisF:symbolInfo是COM对象,getElementId()是实例成员。我不是100%确定它在内部做什么。Head尝试从IEnumerable中检索第一项,但如果找不到,则返回默认值(T)。将.Head(true)更改为.ToList()[0]会产生相同的错误,因此我不认为这是默认值(t)。很遗憾,即使我在使用FILETIME时也会遇到相同的错误。基本上我需要限制我的应用程序的CPU使用。