Skip to content

Latest commit

 

History

History
55 lines (43 loc) · 967 Bytes

EXAMPLES_StringExtensions.md

File metadata and controls

55 lines (43 loc) · 967 Bytes

Back to Package Contents

Instead of

string value = "foo";

if (String.IsNullOrEmpty(value))
{
}

if (String.IsNullOrWhiteSpace(value))
{
}

you can write

using EgonsoftHU.Extensions.Bcl;

string value = "foo";

if (value.IsNullOrEmpty())
{
}

if (value.IsNullOrWhiteSpace())
{
}

Also instead of

void DoSomething(string? input)
{
    const string DefaultValue = "Unknown";

    string value1 =
        String.IsNullOrEmpty(input) ? DefaultValue : input;

    string value2 =
        String.IsNullOrWhiteSpace(input) ? DefaultValue : input;
}

you can write

void DoSomething(string? input)
{
    const string DefaultValue = "Unknown";

    string value1 = input.DefaultIfNullOrEmpty(DefaultValue);

    string value2 = input.DefaultIfNullOrWhiteSpace(DefaultValue);
}