请考虑以下代码:
void Handler(object o, EventArgs e)
{
// I swear o is a string
string s = (string)o; // 1
//-OR-
string s = o as string; // 2
// -OR-
string s = o.ToString(); // 3
}
Run Code Online (Sandbox Code Playgroud)
三种类型的铸造之间有什么区别(好吧,第三种不是铸造,但是你得到了意图).应该首选哪一个?
我有一个类,它有一些类型的属性List<float>,List<int>等等.现在我通过反射查询这个类的属性,以便我得到一个列表PropertyInfo.
我想过滤类型的类型List<>.但比较
propertyInfo.PropertyType == typeof(List<>)
Run Code Online (Sandbox Code Playgroud)
失败.
我可以通过比较名称来解决这个问题,即以下比较工作:
propertyInfo.PropertyType.Name == typeof(List<>).Name
Run Code Online (Sandbox Code Playgroud)
我认为应该有一种更好的方法来比较Generic类型.有线索吗?
好的,我们知道以下两行是等价的 -
(0 == i)(i == 0)此外,过去鼓励使用第一种方法,因为如果您不小心使用'='而不是'==',那么编译器就会给出错误消息.
我的问题是 - 在今天的一代漂亮的IDE和智能编译器中,你还推荐第一种方法吗?
特别是,当我看到以下代码时,这个问题突然出现在我脑海中 -
if(DialogResult.OK == MessageBox.Show("Message")) ...
Run Code Online (Sandbox Code Playgroud)
在我看来,我绝不会推荐上述内容.任何第二意见?
每当我尝试推动我的更改时,我都会收到上述错误.我使用TortoiseHg作为客户.
以下是调试输出hg push:
pushing to https://nulldev@bitbucket.org/nulldev/windows-phone
using https://bitbucket.org/nulldev/windows-phone
proxying through http://[proxy - omitted]
http auth: user nulldev, password not set
sending capabilities command
bitbucket.org certificate successfully verified
[HgKeyring] Keyring URL: https://bitbucket.org/nulldev/windows-phone
[HgKeyring] Looking for password for user nulldev and url https://bitbucket.org/nulldev/windows-phone
[HgKeyring] Keyring password found. Url: https://bitbucket.org/nulldev/windows-phone, user: nulldev, passwd: ********
bitbucket.org certificate successfully verified
query 1; heads
sending batch command
bitbucket.org certificate successfully verified
[HgKeyring] Keyring URL: https://bitbucket.org/nulldev/windows-phone
[HgKeyring] Cached auth data found. Url: https://bitbucket.org/nulldev/windows-phone, user: nulldev, …Run Code Online (Sandbox Code Playgroud) 我有一个像header下面那样的网格布局.div中有一个宽度为的文本1fr.我希望div中的文本在太长时间内被截断.添加text-overflow为ellpsis无效.知道怎么做吗?
它必须是网格,我无法改变它.
html,
body {
height: 100%;
width: 100%;
overflow: hidden;
}
body {
display: flex;
}
.container {
display: flex;
flex-direction: column;
flex: 1;
}
content {
flex: 1;
background-color: red;
}
header {
background-color: limegreen;
display: grid;
grid-template-columns: 0fr 1fr 0fr;
}
header div {
border: 1px solid orange;
}
.long {
text-overflow: ellipsis;
}Run Code Online (Sandbox Code Playgroud)
<div class="container">
<header>
<div>Left</div>
<div class="long">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do …Run Code Online (Sandbox Code Playgroud)我对这个网站上与每个用户相关的可爱的小万花筒图像有点好奇.这些是如何产生的?可能性是:
无论如何,我更感兴趣的是用什么样的算法来生成这样的图像.
我<md-input-container>在Angular组件中使用Material 2 .我想覆盖其中一个类,例如.mat-input-wrapperAngular Material中定义的类.但我想仅覆盖该组件,并且覆盖不应影响页面中的其他组件.
我在WPF中使用以下标记:
<StackPanel.Triggers>
<EventTrigger RoutedEvent="RadioButton.Checked" SourceName="xmlRadioButton">
<EventTrigger.Actions>
<BeginStoryboard Storyboard="{StaticResource ShowXmlPanel}"/>
</EventTrigger.Actions>
</EventTrigger>
<EventTrigger RoutedEvent="RadioButton.Checked" SourceName="adiRadioButton">
<EventTrigger.Actions>
<BeginStoryboard Storyboard="{StaticResource ShowAdiPanel}"/>
</EventTrigger.Actions>
</EventTrigger>
</StackPanel.Triggers>
Run Code Online (Sandbox Code Playgroud)
虽然这在我运行代码时工作正常,但我在VS 2008的设计器窗口中收到以下错误:
值'RadioButton.Checked'无法分配给属性'RoutedEvent'.无效的活动名称.
知道为什么,以及如何解决这个问题?
c# ×2
.net ×1
angular ×1
c ×1
c++ ×1
casting ×1
coding-style ×1
css ×1
css-grid ×1
css3 ×1
data-binding ×1
database ×1
eventtrigger ×1
generics ×1
identicon ×1
mercurial ×1
oop ×1
open-source ×1
tortoisehg ×1
wpf ×1