- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
为什么它的计算结果为false
?
Color.FromArgb(255, 255, 255, 255) == Color.White
更新这是设计使然。
这是 Color
结构中反编译的 Equals
函数的副本:
public override bool Equals(object obj)
{
//probably failure to convert from C++ source,
//the following line should be invalid in C#, nevermind
if (obj is Color)
{
Color color = (Color) obj;
if (((this.value == color.value) &&
(this.state == color.state)) &&
(this.knownColor == color.knownColor))
{
return ((this.name == color.name) ||
(((this.name != null) && (color.name != null)) &&
this.name.Equals(this.name)));
}
}
return false;
}
我的问题是,为什么 MSFT 会让我以丑陋的方式与白人进行比较?!?!?
static bool AreEqual(Color a, Color b)
{
if (!a.Equals(b))
{
return
a.A == b.A &&
a.R == b.R &&
a.G == b.G &&
a.B == b.B;
}
return true;
}
另外,我不明白为什么 Color
中的 FromArgb
函数的 1-arg 重载采用 int
,它应该能够获取一个uint
(0xffffffff
)
最佳答案
This structure only does comparisons with other Color structures. To compare colors based solely on their ARGB values, you should do the following:
if ( color1.ToArgb() == color2.ToArgb()) ...
This is because the .Equals and == operators determine equivalency using more than just the ARGB value of the colors. For example, Color.Black and Color.FromArgb(0,0,0) are not considered equal since Color.Black is a named color and Color.FromArgb(0,0,0) is not.
编辑:其他答案。
My question is why on earth would MSFT have me comparing to white the ugly way?!?!?
如果您比较颜色的方式是想知道它们是否与 ARGB 分量的值完全相同,那么您应该在“丑陋”的方式。如果您以大多数 .NET 程序员使用 Color
结构的方式比较颜色,那么您只想知道某种颜色是 White
还是 Red
或 Chartreuse
,“漂亮”的方式(使用 Equals 和 ==)简单、易于使用且可读性强。
此外,“丑陋”的方法不是您发布的方法,而是这样的:
if (color1.ToArgb() == color2.ToArgb()) ...
这其实并没有那么难看。
Also, another thing I don't get why the 1-arg constructor of Color takes an int, it should be able to take a uint (0xffffffff)
我想说它不应该不能能够接受uint
,因为这会导致不可避免的困惑和颜色错误。编写一个方法来执行此操作很容易。
关于.net - System.Drawing.Color 相等运算符不会将 0xffffffff 视为 Color.White,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8146453/
将“”转换为“>”的主要目的是避免以下内联脚本: var foo = "alert('bug');"; // the value of foo is generated from server
我有以下想法: 在德语中我们有四个额外的字母(ä、ö、ü、ß),我不知道任何其他语言有这些声音,但我认为有口音的法国人也知道这个问题。我们在 Google Play 商店中有很多适用于城市、公交车站、
#!/bin/bash read nameArg find -name "$nameArg" 使用此代码,当我输入例如 *.txt 时,它将为我提供以 txt 结尾的所有文件,但我只想要名称为 *.t
我在 MySQL 5.7.27 中有一个带有 utf8mb4_unicode_ci 排序规则的用户表。 不幸的是, ı 没有像 i 那样进行线程化,例如,以下查询将找不到 Yılmaz select
我的简单 MySQL 查询: SELECT `word` FROM `nouns` WHERE `word` LIKE 'vandenys' 返回: vandenis 但是“vandenYs
虽然我以前用过这样的代码,而且很明显编译器有足够的信息可以工作,但我真的不明白为什么会这样编译: template auto foo(const T& t, I i) { return st
如何实现一个以 int 开头的函数,并在每次(经历有限数量的可能性)返回 1 的几个(例如,5 个) bool 值之一时从中减去 1。 理想情况下的外观是: function list1 list2
因此,如果我的数据库中有一个包含值的表 1 2 3 4 NULL 我执行了查询 SELECT MAX(col1) FROM 我会得到 4。有什么办法可以改变这个,所以 Null 将被视为最大值而不是
例如:我在数据库中有一条记录:[Example] Attena Illusive - 01 [720p].mkv尝试使用查询进行搜索: SELECT ts_rank_cd(to_tsvector('
我试图创建 2 个简单的盒子,并允许用户从 1 个盒子中选择数据,然后将其复制到第二个盒子。如果第二个框中已经有相同的文本,请在后面附加一些简单的文本。 它基本上在该项目不在第二个框中时起作用。但是,
这个问题已经有答案了: How to read a file from jar in Java? (6 个回答) 已关闭10 年前。 我想从我的 *jar 存档中读取文件。我在互联网上阅读了如何从 z
我在 Javascript 中偶然发现了一个我无法理解的极其奇怪的事件。 这是一个非常简单的 if 语句: let hours = 20; 我在这里设置了一个断点,并在调试器中设置了hours = 0
这两个查询给出了完全相同的结果: select * from topics where name='Harligt'; select * from topics where name='Härligt
我有一个包含数值和 NaN 的表格。求和时,如果所选值包含 NaN,则结果将为 NaN。有没有办法让 postgresql 在求和时将它们视为 0 而不是 NaN?或者我只需要将表中的所有 NaN 转
我有一个正在构建的页面,我希望当我滚动(向上或向下)页面时滚动到下一个 div(每个 div 是窗口高度的 100%)。并在那里“固定”,直到您再次滚动。可以在此处看到我正在努力完成的示例: http
我正在用 Javascript 制作一个小的 HTML 页面。它不需要服务器端,但我需要存储这个人所做的事情,所以我正在使用 localStorage。( list ) 如今,浏览器可以选择不存储 c
这两个查询给了我完全相同的结果: select * from topics where name='Harligt'; select * from topics where name='Härligt
我想向 Lua 公开一些 C++ 类。我可以调用Widget:New()获取带有元表集的返回用户数据到表 WidgetMeta . WidgetMeta包含所有 C++ 函数,它是 __index设置
我正在使用一个大型的旧数据库,现在我尝试使用 hibernate 而不是 SQL 来访问它。更大的问题之一是在外键中无限制地使用“0”和“-1”(意思是“NULL”)。 我生成了很多代码,但我手动添加
我试图将一个数字传递到一个 BYTES 数组中 - 但将该数字视为一个字符数组。这是我的代码: for(int i=1;i<=totalFiles;i++) { BYTE* input = n
我是一名优秀的程序员,十分优秀!