How to convert a GUID to a string in C#?

前端 未结 10 937
挽巷
挽巷 2020-12-15 02:20

I\'m new to C#.

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

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

In C#, I\'m trying to do

10条回答
  •  误落风尘
    2020-12-15 03:02

    Following Sonar rules, you should whenever you can try to protect yourself, and use System.globalisation whenever it's possible like for DateTime.ToString().

    So regarding the other answers you could use:

    guid.ToString("", CultureInfo.InvariantCulture)
    

    where "" can be replaces by : N, D, B , P and X for more infos see this comment.

    Example here

提交回复
热议问题