Struct TextSpan
Represents a contiguous range of source text.
public readonly struct TextSpan : IEquatable<TextSpan>
- Implements
- Inherited Members
Constructors
TextSpan(int, int)
Initializes a new instance of the TextSpan struct.
public TextSpan(int start, int length)
Parameters
Exceptions
- ArgumentOutOfRangeException
Thrown when
startorlengthis negative.
Properties
End
Gets the exclusive end offset.
public int End { get; }
Property Value
Exceptions
- OverflowException
Thrown when the end offset exceeds MaxValue.
Length
Gets the span length.
public int Length { get; }
Property Value
Start
Gets the inclusive start offset.
public int Start { get; }
Property Value
Methods
Contains(int)
Determines whether an offset is within the span.
public bool Contains(int offset)
Parameters
offsetintThe Unicode scalar offset.
Returns
- bool
trueif the offset is within the span; otherwise,false.
Exceptions
- OverflowException
Thrown when the span end exceeds MaxValue.
Equals(TextSpan)
public bool Equals(TextSpan other)
Parameters
otherTextSpan
Returns
Equals(object)
public override bool Equals(object obj)
Parameters
objobject
Returns
FromBounds(int, int)
Creates a span from inclusive start and exclusive end offsets.
public static TextSpan FromBounds(int start, int end)
Parameters
Returns
- TextSpan
The span between the specified bounds.
Exceptions
- ArgumentOutOfRangeException
Thrown when
startis negative orendprecedes it.
GetHashCode()
public override int GetHashCode()
Returns
ToString()
public override string ToString()
Returns
Operators
operator ==(TextSpan, TextSpan)
public static bool operator ==(TextSpan left, TextSpan right)
Parameters
Returns
operator !=(TextSpan, TextSpan)
public static bool operator !=(TextSpan left, TextSpan right)