NamespaceSystemLibrary.Common.Net.Extensions SystemLibrary.Common.Net.dll
ReadOnlySpanExtensions
public static class ReadOnlySpanExtensions
Inheritance
System.Object
ReadOnlySpanExtensions
Examples
Arguments
X
Methods
Converts the ReadOnlySpan of Char to a byte array
Returns null if input is null, else byte array
public static byte[] GetBytes(this ReadOnlySpan<char> span, Encoding encoding = null)
X
var textSpan = "Hello World".AsSpan();
var bytes = textSpan.GetBytes();
X
Methods arguments
Type | Name | Description |
---|---|---|
System.ReadOnlySpan<System.Char> | span | |
System.Text.Encoding | encoding |
X
Type | Description |
---|---|
System.Byte[] |
Returns true if the span is not null and length larger than 0 else false
public static bool Is<T>(this ReadOnlySpan<T> span)
X
var textSpan = "Hello World".AsSpan();
var isSpan = textSpan.Is(); // True, span is not null
X
Generic types
Name | Description |
---|---|
T |
Methods arguments
Type | Name | Description |
---|---|---|
System.ReadOnlySpan<T> | span |
X
Type | Description |
---|---|
System.Boolean |
Returns true if the span is null or length is 0 else false
public static bool IsNot<T>(this ReadOnlySpan<T> span)
X
var textSpan = "Hello World".AsSpan();
var isSpan = textSpan.IsNot(); // False, as span is not null, and has text length > 0
X
Generic types
Name | Description |
---|---|
T |
Methods arguments
Type | Name | Description |
---|---|---|
System.ReadOnlySpan<T> | span |
X
Type | Description |
---|---|
System.Boolean |
Convert a ReadOnlySpan to Base64 (only for Char type for time being)
Returns null if input is null, else a Base64 representation of the input
public static string ToBase64(this ReadOnlySpan<char> span, Encoding encoding = null)
X
var textSpan = "Hello World".AsSpan();
var base64 = textSpan.ToBase64();
X
Methods arguments
Type | Name | Description |
---|---|---|
System.ReadOnlySpan<System.Char> | span | |
System.Text.Encoding | encoding |
X
Type | Description |
---|---|
System.String |
}