如何将GUID转换为C#中的字符串? [英] How to convert a GUID to a string in C#?

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

问题描述

我是新的C#。

我知道在vb.net,我可以做到这一点:

I know in vb.net, i can do this:

Dim guid as string = System.Guid.NewGuid.ToString

在C#中,我试图做

String guid = System.Guid.NewGuid().ToString;



但我得到一个不能转换方法组'的ToString'非委托类型'字符串'。你有没有打算调用方法?错误。

推荐答案

您错过了()的ToString 这标志着它作为一个函数调用与函数引用(你传递给与会代表的那种),这亦是为什么C#有没有 AddressOf 运营商,它是由你如何键入它意味着

You're missing the () after ToString that marks it as a function call vs. a function reference (the kind you pass to delegates), which incidentally is why c# has no AddressOf operator, it's implied by how you type it.

试试这个:

string guid = System.Guid.NewGuid().ToString();

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

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