我正在使用 Razor Components,對non-static values在list of objects.我有以下代碼: @page "/CircularGauge/DefaultFunctionalities"@using Syncfusion.EJ2.RazorComponents.CircularGauge <div class="control-section"> <EjsCircularGauge ID="gauge" Axes="axes"></EjsCircularGauge> </div> @functions { int myInteger = 21; public List<Object> axes { get; set; } = new List<Object> { new { radius = "80%", startAngle = 230, endAngle = 130, majorTicks = new { width = "0px" }, minorTicks = new { width = "0px" }, lineStyle = new { width = 8, color = "#E0E0E0" }, labelStyle = new { font = new { fontFamily = "Roboto", size = "12px", fontWeight = "Regular" }, offset = -5 }, pointers = new List<Object> { new { value = 60, radius = "60%", color = "#757575", pointerWidth = 7, cap = new { radius = 8, color = "#757575", border = new { width = 0 } }, needleTail = new { color = "#757575", length = "25%" } }} } }; }來源:https ://ej2.syncfusion.com/aspnet-core-blazor/CircularGauge/DefaultFunctionalities我在我的代碼中使用了一個整數,例如: int myInteger = 21;我想做的是在上面的代碼中: pointers = new List<Object> { new { ****value = 60,**** radius = "60%", color = "#757575", pointerWidth = 7, cap = new { radius = 8, color = "#757575", border = new { width = 0 } } }正在將 的值更改value為我的本地整數,但這是不可能的。這就是為什么我一直在尋找解決方案。有沒有人對此有所了解?
1 回答

墨色風雨
TA貢獻1853條經驗 獲得超6個贊
您正在使用內聯構造函數初始化屬性。您無法訪問內聯構造函數中的實例字段,因為編譯器無法確保先完成哪一個。
您應該將 the 定義myInteger
為 static private static int myInteger
?;蛘吣梢栽跇嬙旌瘮抵薪傩缘闹?,然后您可以在構造函數上使用局部變量。
但是,如果你想定義一個像那個那樣的常量變量,我寧愿建議你更多地這樣做:
private const int MY_INTEGER = 21;
- 1 回答
- 0 關注
- 116 瀏覽
添加回答
舉報
0/150
提交
取消