欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當(dāng)前位置:主頁 > 軟件編程 > C#教程 >

C# 中GUID生成格式的四種方法

來源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C#教程|點(diǎn)擊: 次

C#中GUID的生成以及格式

1、GUID是在System命名空間下的結(jié)構(gòu)(struct)體,下面展示實(shí)例。
(1)創(chuàng)建一個(gè)GUID幫助類(GUIDHelper)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebDemo.guid
{
  public class GuIdHelper
  {
    /// <summary>
    /// GUID生成
    /// </summary>
    /// <param name="format">格式 可填寫N、D、B、P、X</param>
    /// <returns></returns>
    public static string GetNewGuId(string format="")
    {
      if (string.IsNullOrWhiteSpace(format))
        return Guid.NewGuid().ToString();
      else
        return Guid.NewGuid().ToString(format);
    }
  }
}

(2)使用實(shí)例

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace WebDemo.guid
{
  public partial class Index : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {

      StringBuilder str = new StringBuilder();
      string[] array = {"","N","D","B","P","X" };
      foreach (var item in array)
      {
        if (string.IsNullOrWhiteSpace(item))
          str.AppendFormat("默認(rèn)格式:{0}", GuIdHelper.GetNewGuId());
        else
          str.AppendFormat("<br />{0}格式:{1}", item, GuIdHelper.GetNewGuId(item));
      }
      Response.Write(str.ToString());
    }
  }
}

(3)顯示結(jié)果

默認(rèn)格式:4575c4b3-7997-4f11-acd9-f107258e9adc
N格式:a53a7186b583483aa4580519034e8095
D格式:5ae7f002-a989-4345-864b-3bcfbe09e1da
B格式:{d9762660-8461-4c44-b714-8ffad6e1b79c}
P格式:(694ce704-0a7d-41d5-a25a-4eaedf7db50d)
X格式:{0x75198f26,0xac4e,0x42c8,{0x96,0x88,0xcc,0x91,0xe0,0xa6,0x9b,0x21}

在C#中GUID生成的四種格式

var uuid = Guid.NewGuid().ToString(); // 9af7f46a-ea52-4aa3-b8c3-9fd484c2af12 
 
var uuidN = Guid.NewGuid().ToString("N"); // e0a953c3ee6040eaa9fae2b667060e09  
 
var uuidD = Guid.NewGuid().ToString("D"); // 9af7f46a-ea52-4aa3-b8c3-9fd484c2af12 
 
var uuidB = Guid.NewGuid().ToString("B"); // {734fd453-a4f8-4c5d-9c98-3fe2d7079760} 
 
var uuidP = Guid.NewGuid().ToString("P"); // (ade24d16-db0f-40af-8794-1e08e2040df3) 
 
var uuidX = Guid.NewGuid().ToString("X"); // {0x3fa412e3,0x8356,0x428f,{0xaa,0x34,0xb7,0x40,0xda,0xaf,0x45,0x6f}} 

參考:https://msdn.microsoft.com/en-us/library/97af8hh4.aspx

上一篇:C# string格式的日期時(shí)間字符串轉(zhuǎn)為DateTime類型的方法

欄    目:C#教程

下一篇:c# DevExpress gridcontrol日期行的顯示格式設(shè)置

本文標(biāo)題:C# 中GUID生成格式的四種方法

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/5896.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有