/// <summary>
/// Create only 1 instance of <see cref="T" /> per thread. (Only unique when using this method!)
/// </summary>
/// <typeparam name="T"></typeparam>
public static class Cache<T> where T : notnull, new() {
private static ThreadLocal<T> LocalCache { get; } = new(() => new T(), false);
public static T? Instance { get; } = LocalCache.Value;
}
Like this:
Like Loading...
Related
Published by Protiguous
C# Software Developer, SQL Server DBA, Father, and seeker of Truth.
View all posts by Protiguous