C#,VS 2010
我需要确定浮点值是否为NaN.
使用测试NaN的浮点数
float.IsNaN(aFloatNumber)
Run Code Online (Sandbox Code Playgroud)
堆栈溢出崩溃.
那样做
aFloatNumber.CompareTo(float.NaN).
Run Code Online (Sandbox Code Playgroud)
以下不会崩溃,但它无用,因为它返回NaN,无论如何:
aFloatNumber - float.NaN
Run Code Online (Sandbox Code Playgroud)
搜索"堆栈溢出"会返回有关此网站的结果,而不是实际堆栈溢出的结果,因此我找不到相关的答案.
为什么我的应用程序在测试NaN时会进入堆栈溢出?
编辑:调用堆栈:

编辑:我的代码中显然有些东西:这句话:
bool aaa = float.IsNaN(float.NaN);
Run Code Online (Sandbox Code Playgroud)
所以,这就是我在做的事情:
编辑:
Debug.WriteLine()显示代码只执行一次:没有递归.
编辑:
这有效:
float fff = 0F;
int iii = fff.CompareTo(float.PositiveInfinity);
Run Code Online (Sandbox Code Playgroud)
这崩溃了:
float fff = 0F;
int iii = fff.CompareTo(float.NaN);
Run Code Online (Sandbox Code Playgroud) 我的应用程序是使用visual studio 2010 express创建的,除了XP之外,在所有Windows版本中看起来都很好.
XP在某些标签的开头添加了一个额外的方形字符.

所有标签的属性,无论它们是否显示额外字符,都是相同的:
唯一的区别是位置,宽度,当然还有文本.
它似乎与使用Omega等特殊字符无关.它与宽度无关.
形成(应用程序).Designer.cs:
这个标签没问题:
// label22
//
this.label22.AutoSize = true;
this.label22.Location = new System.Drawing.Point(58, 23);
this.label22.Name = "label22";
this.label22.Size = new System.Drawing.Size(20, 13);
this.label22.TabIndex = 32;
this.label22.Text = "Ah";
Run Code Online (Sandbox Code Playgroud)
这个标签增加了一个有趣的角色
// lblPackCurrUnits
//
this.lblPackCurrUnits.AutoSize = true;
this.lblPackCurrUnits.Location = new System.Drawing.Point(44, 300);
this.lblPackCurrUnits.Name = "lblPackCurrUnits";
this.lblPackCurrUnits.Size = new System.Drawing.Size(14, 13);
this.lblPackCurrUnits.TabIndex = 17;
this.lblPackCurrUnits.Text = "?A";
Run Code Online (Sandbox Code Playgroud)
知道是什么导致的吗?
好吧,好吧!看那儿!最后一行有一个有趣的角色! 将代码粘贴到stackoverflow中会发现问题!
那里有很多有趣的人物.只是它们在Visual Studio文本编辑器中以及我尝试过的任何其他编辑器中都是不可见的.它们只在我粘贴在这里时出现!谁创造了它们?
好的,我有我的解决方案:我将手工编辑Designer.cs文件.
但我在这里保留这个问题,以便其他人可以从中受益.
我有一个数组,每个数组的元素可以是uint16_t或一对uint8_t.
它的元素被定义为uint16_t和2 uint8_t的子数组的并集.
不幸的是,编译器(MicroChip XC16)分配的内存量应该是阵列的两倍.
typedef union {
uint16_t u16; // As uint16_t
uint8_t u8[2]; // As uint8_t
} my_array_t;
my_array_t my_array[1]; // 1 word array, for testing
my_array[0].u8[0] = 1;
my_array[0].u8[1] = 2;
uint8_t byte_0 = my_array[0].u8[0]; // Gets 0x01
uint8_t byte_1 = my_array[0].u8[1]; // Gets 0x02
uint16_t byte_0 = my_array[0].u16; // Gets 0x0201
Run Code Online (Sandbox Code Playgroud)
编译器应该分配4个字节而不是2个字节.
解决方法:如果我将结构更改为:
typedef union {
uint16_t u16; // As uint16_t
uint8_t u8[1]; // As uint8_t
} my_array_t;
Run Code Online (Sandbox Code Playgroud)
编译器应该分配2个字节,但这是不正确的:
my_array[0].u8[1] = 2;
Run Code Online (Sandbox Code Playgroud)
虽然它仍然有效:
uint8_t byte_1 = …Run Code Online (Sandbox Code Playgroud) 与组装相比,C中的标志处理感觉很麻烦.
我正在寻找一种方法,使C代码可以像汇编一样可读.
在大会中:
#define powerOn flagsByte,0
...
bsf powerOn ; Turn on the power
bcf powerOn ; Turn off the power
btfsc powerOn ; If the power is on...
Run Code Online (Sandbox Code Playgroud)
在C:
flagsByte |= (1 << 0) ; // Turn on the power
flagsByte &= ~(1 << 0) ; // Turn off the power
if (flagsByte & (1 << 0)); // If the power is on...
Run Code Online (Sandbox Code Playgroud)
在C中,用宏:
#define BIT_SET(var,bitNo) (var |= (1<<(bitNo)))
BIT_SET(flagsByte,0) ; // Turn on the power
Run Code Online (Sandbox Code Playgroud)
这可行,但它仍然不如装配中那么干净.
我喜欢这样做:
#define …Run Code Online (Sandbox Code Playgroud) 在 Windows 窗体中。
我有一个自定义控件,它只包含一个控件:PictureBox。
public partial class VarIllumButton : UserControl
Run Code Online (Sandbox Code Playgroud)
它使用 OnLoad 方法:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e); // Handle the default function
pictureBox.Image = image0;
}
Run Code Online (Sandbox Code Playgroud)
由于自定义控件只有1个控件,我希望将其更改为:
public partial class VarIllumButton : PictureBox
Run Code Online (Sandbox Code Playgroud)
但后来我得到一个错误
'System.Windows.Forms.PictureBox' does not contain a definition for 'OnLoad'
Run Code Online (Sandbox Code Playgroud)
然而,我看到Control 类确实有一个 OnLoad 方法:
您能想到为什么我可以从 UserControl 访问它,但不能从 Control 访问它吗?
是否有另一种方法可以在控件完成加载时调用?
使用指定大小的数组,如果我在初始化中放置了太多元素,编译器会发出警告:
int array[3] = {1,2,3,4}; // Warning
Run Code Online (Sandbox Code Playgroud)
但是,当然,如果我放置太少的元素(它只是用0填充它们)它不会这样做:
int array[3] = {1,2}; // OK (no warning)
Run Code Online (Sandbox Code Playgroud)
但是,我必须确保在编译时我在N元素数组的初始化中指定了N个元素(它是一个函数指针数组).
如果指定的元素太少,我可以让编译器发出警告吗?
如何在左上角标题单元格中设置文本是数据网格视图?

我有很多相同的组合框。在设计时,我只设置了第一个的元素。在运行时,我想将第一个项目复制到其他项目。
我可以轻松地从第一个项目中获得项目。但我无法分配其他框的项目:ComboBox.Items 是只读的。
我可以使用循环来迭代所有项目并使用 ComboBox.Items.Add() 方法。
有没有一种方法可以一步完成,而不需要迭代每一项?