Created
July 8, 2024 06:01
-
-
Save akeit0/66705b94176102e2b9f179f2f142a23d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections; | |
| using System.Collections.Generic; | |
| using System.Runtime.CompilerServices; | |
| PArray<int> pArray=[1,2,3,4]; | |
| pArray[1..3]=[0,0]; | |
| Console.WriteLine(pArray[0]); | |
| Console.WriteLine(pArray[1]); | |
| Console.WriteLine(pArray[2]); | |
| Console.WriteLine(pArray[3]); | |
| public partial struct PArray<T>(T[] array){ | |
| public PArray<T> this[Range range]{ | |
| get=>new (array[range]); | |
| set=> value.AsSpan().CopyTo(array.AsSpan()[range]); | |
| } | |
| public ref T this[int index]=>ref array[index]; | |
| Span<T> AsSpan()=>array.AsSpan(); | |
| } | |
| //ここから下はコレクション式[]で書くための部分 | |
| public class PArray(){ | |
| public static PArray<T> Create<T>(ReadOnlySpan<T> span)=>new PArray<T>(span.ToArray()); | |
| } | |
| [CollectionBuilder(typeof(PArray), "Create")] | |
| public partial struct PArray<T>:IEnumerable<T> { | |
| #region ICollectionImpl | |
| public IEnumerator<T> GetEnumerator() | |
| { | |
| throw new NotImplementedException(); | |
| } | |
| IEnumerator IEnumerable.GetEnumerator() | |
| { | |
| throw new NotImplementedException(); | |
| } | |
| #endregion | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1 | |
| 0 | |
| 0 | |
| 4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "version": 1, | |
| "target": "Run", | |
| "mode": "Debug", | |
| "branch": "features-ParamsCollections" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment