Guid mainfolderid = (main.GetValue(""));
其中 main
是一个动态实体。
如何将上面提到的 main.GetValue("")
转换为 System.Guid
?
错误说
Cannot implicitly convert type object to 'System.Guid'.
最佳答案
GetValue
方法实际上是否返回类型为 object
的 Guid
?如果是这样,那么您只需要像这样执行显式转换:
Guid mainfolderid = (Guid)main.GetValue("");
如果不是,GetValue
是否返回可以传递给其中一个构造函数的内容(即 byte[]
或 string
) ?在这种情况下,您可以这样做:
Guid mainfolderid = new Guid(main.GetValue(""));
如果以上都不适用,那么您将需要进行一些手动操作,将 GetValue
返回的任何内容转换为 Guid
。
关于c# - 将对象转换为 System Guid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3805984/