"converter best practice for better performance" Code Answer

5

the most performant would be to use private static readonly as follows

private static readonly color color1 = (color)colorconverter.convertfromstring("#fcd44e");
private static readonly color color2 = (color)colorconverter.convertfromstring("#fcd666");

public object convert(object value, type targettype, object parameter, system.globalization.cultureinfo culture)
{
    if ((int)value == 1)
        return color1;

    return color2;
}

see this answer for good discussion: method can be made static, but should it?

By Simon1979 on September 25 2022

Answers related to “converter best practice for better performance”

Only authorized users can answer the Search term. Please sign in first, or register a free account.