Skip to content

Instantly share code, notes, and snippets.

@cdock1029
Created March 5, 2025 04:25
Show Gist options
  • Select an option

  • Save cdock1029/26bfbe1cae3af1fd8cd8f6b09065c965 to your computer and use it in GitHub Desktop.

Select an option

Save cdock1029/26bfbe1cae3af1fd8cd8f6b09065c965 to your computer and use it in GitHub Desktop.
Converter accessing previous data
@page "/demo"
<h2>Items Diff</h2>
<div class="flex items-end">
@foreach ((int idx, int n) in _nums.Index())
{
<div class="mx-4 w-20">
@{
int diff = @Diff(_nums, idx);
}
<span>Diff = @diff</span>
<div class="@(diff > 0 ? "bg-green-400" : "bg-red-400") flex flex-col items-center justify-end text-2xl"
style="height: @(n)0px;">
@n
</div>
</div>
}
</div>
@code {
private readonly List<int> _nums = [24, 13, 15, 20, 17, 25];
static int Diff(List<int> list, int idx)
{
return idx == 0 ? list[0] : list[idx] - list[idx - 1];
}
}
@cdock1029
Copy link
Author

output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment