String.Create<TState>(Int32, TState, SpanAction<Char,TState>) 메서드 (System) | Microsoft Docs
String.Create<TState>(Int32, TState, SpanAction<Char,TState>) 메서드 (System)
특정 길이의 새 문자열을 만든 다음 지정된 콜백을 사용하여 문자열을 초기화합니다.Creates a new string with a specific length and initializes it after creation by using the specified callback.
docs.microsoft.com
Byte 배열을 Hex(16진수) 문자열로 변환하는 방법 - 📌 자유게시판 - 닷넷데브 (dotnetdev.kr)
Byte 배열을 Hex(16진수) 문자열로 변환하는 방법
호오. 자주 가는 사이트에 제목과 유사한 글이 올라와 있었습니다. 그 글을 공유하려다가… 이런 종류의 문제는 구현 자체가 어렵지는 않아서, 일종의 코드 경진을 해보면 어떨까 해서 올려봅니
forum.dotnetdev.kr
https://forum.dotnetdev.kr/t/net-c-string-create-tstate/2639/3?u=tjdskaqks
[.NET / C#] String.Create<TState>()
System.Span<T> 을 이용하여 문자열 버퍼에 복사하고 현재 컨텍스트 상태가 캡쳐되지 않도록 정적 익명 함수를 사용하면 더욱 좋은 코드가 될것 같습니다 🙂 string str1 = "Hello"; string str2 = "World"; int le
forum.dotnetdev.kr
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
string str1 = "Hello" + Environment.NewLine;
string str2 = "World" + Environment.NewLine;
string str3 = "brad";
int length = str1.Length + str2.Length + str3.Length;
// 1. String 할당과 함께 str1, str2 복사
var result = string.Create(length, (str1, str2, str3), static (buffer, args) =>
{
var (str1, str2, str3) = args;
str1.AsSpan().CopyTo(buffer);
str2.AsSpan().CopyTo(buffer[str1.Length..]);
str3.AsSpan().CopyTo(buffer[(str1.Length + str2.Length)..]);
});
Console.WriteLine(result);
Console.ReadLine();
}
}
}
'C#' 카테고리의 다른 글
[C#] EF Core 간단 사용. (0) | 2022.05.26 |
---|---|
[C#] .NET 6 - Worker Service Environment.Exit (0) | 2022.04.27 |
[C#] FormBorderStyle None 사용시 아이콘, Resize, Move, taskbar click to minimize (2) | 2022.02.18 |
[C#] System.Text.Json.JsonSerializer.Serialize 할 때 한글이 유니코드 형식으로 출력 될 때 (0) | 2022.02.11 |
[C#] .NET 6 - NativeMemory 사용 (0) | 2022.01.12 |