c# - 将对象转换为 System Guid

标签 c#

Guid mainfolderid = (main.GetValue(""));

其中 main 是一个动态实体。

如何将上面提到的 main.GetValue("") 转换为 System.Guid

错误说

Cannot implicitly convert type object to 'System.Guid'.

最佳答案

GetValue 方法实际上是否返回类型为 objectGuid?如果是这样,那么您只需要像这样执行显式转换:

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/

相关文章:

c# - Entity Framework 6 on MVVM + PRISM 模式

c# - 用户控件上的按钮监听器

c# - Asp.net 强制保存详细信息 View /表单 View

C# 2022 IDE - 没有关于代码样式或变量命名的警告?

c# - ToolStripControlHost始终位于顶部(C#窗口形式)

c# - 定位windows系统日期时间时钟窗口

c# - Entity Framework 和Mysql事务

C# Do-Loop 不向字符串添加字符

c# - 如何使用 NUnit 在 .NET Core 中模拟 UserManager?

c# - 为什么我的 Windows Media Player 组件没有添加到 Visual Studio 2019 中的 WinForms 工具箱中?