[.NET / C#] String.Create<TState>()

μ•ˆλ…•ν•˜μ„Έμš”~

νšŒμ‚¬ μƒν™œμ΄ λ°”λΉ μ„œ κ°„λ§Œμ— 글을 μž‘μ„±ν•˜κ²Œ λ˜λ„€μš” γ…Žγ…Ž

μ΄λ²ˆμ—” String.Create() ν•¨μˆ˜μ— λŒ€ν•΄ 글을 적어 λ³΄μ•˜μŠ΅λ‹ˆλ‹€.

의견 μžˆμœΌμ‹œλ©΄ 곡유 뢀탁 λ“œλ¦¬κ² μŠ΅λ‹ˆλ‹€.

11 Likes

κ΄€λ ¨ν•΄μ„œ μ—λ°˜μ΅œλ‹˜μ˜ 글이 λ– μ˜¬λΌ 링크 κ±Έμ–΄λ΄…λ‹ˆλ‹€.

5 Likes

System.Span<T> 을 μ΄μš©ν•˜μ—¬ λ¬Έμžμ—΄ 버퍼에 λ³΅μ‚¬ν•˜κ³ 
ν˜„μž¬ μ»¨ν…μŠ€νŠΈ μƒνƒœκ°€ μΊ‘μ³λ˜μ§€ μ•Šλ„λ‘ 정적 읡λͺ… ν•¨μˆ˜λ₯Ό μ‚¬μš©ν•˜λ©΄ λ”μš± 쒋은 μ½”λ“œκ°€ 될것 κ°™μŠ΅λ‹ˆλ‹€ :slight_smile:

string str1 = "Hello";
string str2 = "World";

int length = str1.Length + str2.Length;

// 1. String ν• λ‹Ήκ³Ό ν•¨κ»˜ str1, str2 볡사
var result = string.Create(length, (str1, str2), static (buffer, args) =>
{
    var (str1, str2) = args;
    str1.AsSpan().CopyTo(buffer);
    str2.AsSpan().CopyTo(buffer[str1.Length..]);
});
5 Likes

정적 읡λͺ… ν•¨μˆ˜λ‘œ 캑쳐λ₯Ό λ§‰μœΌλ©΄ λ”μš± μ˜λ„λ₯Ό λͺ…ν™•ν•΄ ν•΄μ£Όκ² λ„€μš”. 쒋은 정보 κ°μ‚¬ν•©λ‹ˆλ‹€ :slight_smile:

3 Likes