我有这个 Blazor 页面
@page "/bearoffdata"
@using BlazorBoinq.Components
<h3>Bearoff Data</h3>
<Position_Hex_IdPair />
<PositionData />
@code {
}
Run Code Online (Sandbox Code Playgroud)
使用这两个 Razor 组件:
@using BlazorBoinq.Data
@using BgBearoffCoreNamespace;
@inject BgBearoffService BoService
<label>Position</label>
<input type="text" spellcheck="false" @bind-value="@PositionText" @bind-value:event="oninput" />
<span> = </span>
<input type="number" step="1" @bind-value="@PositionId" @bind-value:event="oninput" />
<label>Id</label>
@code {
BgBearoffCore BgBo;
protected override async Task OnInitializedAsync()
{
BgBo = await BoService.GetBgBearoffAsync();
}
private Int64 positionId;
private String positionText;
protected Int64 PositionId
{
get => positionId;
set
{
positionId = value;
if (positionId > 0 …Run Code Online (Sandbox Code Playgroud) 我有一个包含两个组件的 Blazor 页面。其中一个组件有一个按钮,单击该按钮会生成一个随机数。另一个组件有一个文本区域,应显示生成的随机数。
<h1>Parent Page</h1>
<ProvideNumberComponent />
<DisplayNumberComponent />
@code {
}
Run Code Online (Sandbox Code Playgroud)
<h3>Provides Number</h3>
<button class="btn btn-primary" @onclick="CalculateNumber">Provide Number</button>
@code {
private void CalculateNumber(MouseEventArgs e)
{
Random rnd = new Random();
Int32 nextNumber = rnd.Next();
}
}
Run Code Online (Sandbox Code Playgroud)
<h3>Displays number</h3>
<textarea cols="9" rows="1" readonly style="font-family:monospace;" />
@code {
}
Run Code Online (Sandbox Code Playgroud)
从计算同级组件获取数字以显示在显示同级组件中的最简洁方法是什么?
我的代码的一个问题是,随机对象是在每次单击按钮时实例化的,而不是在初始化时实例化一次。通过将 Random 对象放置在单例服务类中并将其注入计算组件是否可以最好地解决这个问题?
假设我有一个像这样的 UInt128
UInt64 upperA = 7, lowerA = 8;
UInt128 foo = new(upperA, lowerA);
++foo;
Run Code Online (Sandbox Code Playgroud)
现在我想从更新后的 foo 中提取两个 UInt64。
如果它们是财产,我可以这样做
UInt64 upperB = foo.Upper, lowerB = foo.Lower;
Run Code Online (Sandbox Code Playgroud)
但它们不是,那么我如何获得它们呢?
这是代码:
int[,] Arr;
Arr = Array.Empty();
Run Code Online (Sandbox Code Playgroud)
这是第二行的编译错误:
错误 CS0411 无法从用法推断方法“Array.Empty()”的类型参数。尝试显式指定类型参数。
这应该是一个简单的语法修复,但我一直无法得到它。
我想将以下内容传递给 c 中的函数:
#define GPIO_PORTF_DATA_R (*((volatile unsigned long *)0x400253FC))
Run Code Online (Sandbox Code Playgroud)
以下似乎工作得很好:
void ZeroRegister(unsigned long * _REG)
{
#define vReg (*((volatile unsigned long *)_REG))
vReg = 0;
}
Run Code Online (Sandbox Code Playgroud)
有更好的方法来编码吗?或者我的代码有缺陷?除了它生成的编译器警告之外。