Table of Contents

Class CharExtensions

Namespace
Cuemon.Extensions
Assembly
Cuemon.Extensions.Core.dll

Extension methods for the char struct.

public static class CharExtensions
Inheritance
CharExtensions

Examples

The following example demonstrates converting sequences of values to strings and string sequences using the <xref:Cuemon.Extensions.CharExtensions.ToEnumerable(System.Collections.Generic.IEnumerable{char})> and <xref:Cuemon.Extensions.CharExtensions.FromChars(System.Collections.Generic.IEnumerable{char})> extension methods.

using System;
using System.Collections.Generic;
using System.Linq;
using Cuemon.Extensions;

namespace MyApp.Examples;

public static class CharExtensionsExample
{
    public static void Demonstrate()
    {
        char[] chars = "Hello World".ToCharArray();
        string text = chars.FromChars();
        IEnumerable<string> strings = chars.ToEnumerable();
        string alphabet = Enumerable.Range('A', 26).Select(c => (char)c).FromChars();

        Console.WriteLine(text);
        Console.WriteLine(strings.Count());
        Console.WriteLine(alphabet);
    }
}

Methods

FromChars(IEnumerable<char>)

Converts the specified values to its equivalent string representation.

public static string FromChars(this IEnumerable<char> values)

Parameters

values IEnumerable<char>

The IEnumerable{char} to extend.

Returns

string

A string equivalent to the specified values.

Exceptions

ArgumentNullException

values cannot be null.

ToEnumerable(IEnumerable<char>)

Converts the specified values to its equivalent IEnumerable{string}.

public static IEnumerable<string> ToEnumerable(this IEnumerable<char> values)

Parameters

values IEnumerable<char>

The IEnumerable{char} to extend.

Returns

IEnumerable<string>

An IEnumerable{string} equivalent to the specified values.

Exceptions

ArgumentNullException

values cannot be null.