Baza wiedzyCentrum egzaminacyjne
PLPolski
Wybierz język13

CKTIS / C#

System.Guid: odniesienie praktyczne

System.Guid: odniesienie praktyczne: Guid jest 128-bitowym identyfikatorem z kilkoma formatami tekstowymi.

Wersja: .NET API; verified on .NET 10.0.14

Składnia

System.Guid /* select a documented member or constructor */

Guid jest 128-bitowym identyfikatorem z kilkoma formatami tekstowymi.

Stosuj jako praktycznie unikalny identyfikator, gdy nie potrzebujesz tajności ani naturalnego porządku.

Guid nie jest sekretem i losowa kolejność może fragmentować indeksy baz danych.

Parse błędnego tekstu zgłasza FormatException; TryParse zwraca false, a Empty to same zera.

Kompletny program rzeczywiście używa System.Guid; oczekiwany stdout to dokładnie 00112233445566778899aabbccddeeff.

Przykłady

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;

var id = Guid.Parse("00112233-4455-6677-8899-aabbccddeeff");
Console.WriteLine(id.ToString("N"));

Wynik

00112233445566778899aabbccddeeff

Kompletny program rzeczywiście używa `System.Guid`; oczekiwany stdout to dokładnie `00112233445566778899aabbccddeeff`.

Źródła