如何将字符串转换为GUID [英] How to convert a string to a Guid

查看:798
本文介绍了如何将字符串转换为GUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有找到该GUID的方法的TryParse。 。我不知道别人如何处理通过转换字符串格式一个GUID为一个GUID类型

 的Guid标识; 

{
n =新的GUID(的Request.QueryString [身份证]);
}

{
n = Guid.Empty;
}


解决方案

 新的GUID(字符串)

您也可以看看使用类型转换器


I did not find the TryParse method for the Guid. I’m wondering how others handle converting a guid in string format into a guid type.

Guid Id;
try
{
    Id = new Guid(Request.QueryString["id"]);
}
catch
{
    Id = Guid.Empty;
}

解决方案

new Guid(string)

You could also look at using a TypeConverter.

这篇关于如何将字符串转换为GUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆