Skip to content

Instantly share code, notes, and snippets.

@akeit0
Created July 8, 2024 06:01
Show Gist options
  • Select an option

  • Save akeit0/66705b94176102e2b9f179f2f142a23d to your computer and use it in GitHub Desktop.

Select an option

Save akeit0/66705b94176102e2b9f179f2f142a23d to your computer and use it in GitHub Desktop.
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
}
{
"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