-
Please tell me if this code can work? I did another extension method ToIndexable() to make this kind of thing work. public record struct ArrayIndexedEnumerator<T>(T[] array) : IEnumerator<(int, T)>
{
private int _index = -1;
public bool MoveNext()
{
_index++;
return _index < array.Length;
}
public void Reset()
{
_index = -1;
}
public (int, T) Current => (_index, array[_index]);
object IEnumerator.Current => Current;
public void Dispose()
{
}
}
public static ArrayIndexedEnumerator<T> GetEnumerator<T>(this T[] array) => new(array);
static void Test()
{
foreach ((int, int) xx in new[] { 1, 2, 3 }) // Error -> Cannot convert element type 'int' to iterator type '(int, int)`
{
}
foreach (var (idx, elem) in new[] { 1, 2, 3 }) // No 'Deconstruct' method with 2 out parameters found for type 'int'
{
}
} context: <div class="py-8 flex flex-col gap-4">
@foreach (var (currentIndex, title) in new[] // <---
{
"Less than $25k", "$25k to 100$k", "$100k to $300k", "$300k to $500k", "$500k to $1M", "$1M or more"
}.ToIndexable()) // <---
{
<label>
<input type="radio" class="peer absolute w-0 h-0" @onclick="() => selected = currentIndex"/>
<div class="flex px-4 py-8 h-12 items-center justify-between shadow-sm cursor-pointer rounded-md bg-gray-300">
<span class="ml-3 font-medium text-xl">@title</span>
<span class="mr-3 h-6 w-6 rounded-[50%] bg-white border-solid border border-black
@If(selected == currentIndex, "border-blue-700 border-[4px]")"></span>
</div>
</label>
}
</div> |
Beta Was this translation helpful? Give feedback.
Answered by
HaloFour
Nov 5, 2022
Replies: 1 comment 1 reply
-
The extension method is the suggested route. See: #1584 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
En3Tho
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The extension method is the suggested route.
See: #1584