UNSAFECSHARP Telegram 83
Интересное.

public T A<T>() where T : struct {
var t = new T();
...
return t;
}

Вот такой код мы обычно воспринимаем как "сделать default значение и потом мы его вернем". Все бы ничего, но это не совсем так. Вот как будет выглядеть этот код:

public T A<T>() where T : struct {
var t = System.Activator.CreateInstance<T>();
...
return t;
}


Исправить это довольно просто:

public T A<T>() where T : struct {
T t = default;
...
return t;
}


#performance #lifehack #structs
👍261



tgoop.com/unsafecsharp/83
Create:
Last Update:

Интересное.

public T A<T>() where T : struct {
var t = new T();
...
return t;
}

Вот такой код мы обычно воспринимаем как "сделать default значение и потом мы его вернем". Все бы ничего, но это не совсем так. Вот как будет выглядеть этот код:

public T A<T>() where T : struct {
var t = System.Activator.CreateInstance<T>();
...
return t;
}


Исправить это довольно просто:

public T A<T>() where T : struct {
T t = default;
...
return t;
}


#performance #lifehack #structs

BY Unity: Всё, что вы не знали о разработке


Share with your friend now:
tgoop.com/unsafecsharp/83

View MORE
Open in Telegram


Telegram News

Date: |

According to media reports, the privacy watchdog was considering “blacklisting” some online platforms that have repeatedly posted doxxing information, with sources saying most messages were shared on Telegram. ‘Ban’ on Telegram Telegram users themselves will be able to flag and report potentially false content. In the next window, choose the type of your channel. If you want your channel to be public, you need to develop a link for it. In the screenshot below, it’s ”/catmarketing.” If your selected link is unavailable, you’ll need to suggest another option. How to create a business channel on Telegram? (Tutorial)
from us


Telegram Unity: Всё, что вы не знали о разработке
FROM American