File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed
docs/csharp/language-reference/operators/snippets/shared Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 1010public class LineBuffer : IEnumerable < char >
1111{
1212 private readonly char [ ] _buffer = new char [ 80 ] ;
13+ private readonly int _count ;
1314
1415 public LineBuffer ( ReadOnlySpan < char > buffer )
1516 {
@@ -18,10 +19,30 @@ public LineBuffer(ReadOnlySpan<char> buffer)
1819 {
1920 _buffer [ i ] = buffer [ i ] ;
2021 }
22+ _count = number ;
2123 }
2224
23- public IEnumerator < char > GetEnumerator ( ) => _buffer . AsEnumerable < char > ( ) . GetEnumerator ( ) ;
24- IEnumerator IEnumerable . GetEnumerator ( ) => _buffer . GetEnumerator ( ) ;
25+ public int Count => _count ;
26+
27+ public char this [ int index ]
28+ {
29+ get
30+ {
31+ if ( ( uint ) index >= ( uint ) _count )
32+ throw new IndexOutOfRangeException ( ) ;
33+ return _buffer [ index ] ;
34+ }
35+ }
36+
37+ public IEnumerator < char > GetEnumerator ( )
38+ {
39+ for ( int i = 0 ; i < _count ; i ++ )
40+ {
41+ yield return _buffer [ i ] ;
42+ }
43+ }
44+
45+ IEnumerator IEnumerable . GetEnumerator ( ) => GetEnumerator ( ) ;
2546
2647 // etc
2748}
Original file line number Diff line number Diff line change 22
33 <PropertyGroup >
44 <OutputType >Exe</OutputType >
5- <TargetFramework >net8 .0</TargetFramework >
5+ <TargetFramework >net10 .0</TargetFramework >
66 <Nullable >enable</Nullable >
77 <AllowUnsafeBlocks >true</AllowUnsafeBlocks >
88 <ImplicitUsings >true</ImplicitUsings >
You can’t perform that action at this time.
0 commit comments