请使用以下代码(可用作控制台应用程序):
static void Main(string[] args)
{
int i = 0;
i += i++;
Console.WriteLine(i);
Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)
结果i是0.我预计2(正如我的一些同事所做的那样).编译器可能会创建某种导致i为零的结构.
我期望2的原因是,在我的思路中,右手语句将首先被评估,用1递增i.比它被添加到i.因为我已经是1,所以它加1比1.所以1 + 1 = 2.显然这不是正在发生的事情.
你能解释一下编译器的作用或运行时会发生什么吗?为什么结果为零?
某种免责声明:我绝对知道你不会(也可能不会)使用这段代码.我知道我永远不会.尽管如此,我发现知道为什么它以这种方式行动以及究竟发生了什么是很有趣的.
请考虑以下HTML:
<html>
<head>
<style>
TABLE.data TD.priceCell
{
background-color: #EEE;
text-align: center;
color: #000;
}
div.datagrid table
{
border-collapse: collapse;
}
div.datagrid table tbody
{
position: relative;
}
</style>
</head>
<body>
<div id="contents" class="datagrid">
<table class="data" id="tableHeader">
<thead>
<tr class="fixed-row">
<th>Product</th>
<th class="HeaderBlueWeekDay">Price</th>
<th class="HeaderBlueWeekDay">Discount</th>
</tr>
</thead>
<tbody>
<tr style="font-style: italic;">
<td>Keyboard</td>
<td class="priceCell">20</td>
<td style="border-right: #3D84FF 1px solid; border-left: #3D84FF 1px solid;" class="priceCell">2</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
请注意,最后一个单元格的内联样式具有左边框和右边框.你(或至少我)会期望这是可见的.在IE中,情况就是这样.但在Firefox(6)中,事实并非如此.你可以通过以下方式解决
div.datagrid table tbody在CSS中删除相对位置div.datagrid table tbody到div.datagrid …我有一个WPF组合框,它充满了,例如,客户对象.我有一个DataTemplate:
<DataTemplate DataType="{x:Type MyAssembly:Customer}">
<StackPanel>
<TextBlock Text="{Binding Name}" />
<TextBlock Text="{Binding Address}" />
</StackPanel>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
这样,当我打开我的ComboBox时,我可以看到不同的客户的姓名,以及下面的地址.
但是当我选择一个Customer时,我只想在ComboBox中显示Name.就像是:
<DataTemplate DataType="{x:Type MyAssembly:Customer}">
<StackPanel>
<TextBlock Text="{Binding Name}" />
</StackPanel>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
我可以为ComboBox中的所选项目选择另一个模板吗?
解
在答案的帮助下,我解决了这个问题:
<UserControl.Resources>
<ControlTemplate x:Key="SimpleTemplate">
<StackPanel>
<TextBlock Text="{Binding Name}" />
</StackPanel>
</ControlTemplate>
<ControlTemplate x:Key="ExtendedTemplate">
<StackPanel>
<TextBlock Text="{Binding Name}" />
<TextBlock Text="{Binding Address}" />
</StackPanel>
</ControlTemplate>
<DataTemplate x:Key="CustomerTemplate">
<Control x:Name="theControl" Focusable="False" Template="{StaticResource ExtendedTemplate}" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ComboBoxItem}}, Path=IsSelected}" Value="{x:Null}">
<Setter TargetName="theControl" Property="Template" Value="{StaticResource SimpleTemplate}" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</UserControl.Resources> …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置禁用的输入.我可以用:
.myInput[disabled] { }
Run Code Online (Sandbox Code Playgroud)
要么
.myInput:disabled { }
Run Code Online (Sandbox Code Playgroud)
属性选择器是现代CSS3方式和前进的方式吗?我曾经使用伪类,但是我找不到任何关于它们是否旧的方式并且不会被支持的信息,或者它们是否相等而且你可以使用你最喜欢的任何东西.
我不需要支持旧的浏览器(它是一个内部网应用程序),所以它是:
我在Visual Studio 2015中创建了一个新的ASP.NET Core Web应用程序.我还设置了一个Azure Web应用程序,以便从GitHub中提取应用程序并运行它.这工作正常,但我无法连接到Azure上的数据库.
在本地,这是有效的,它使用config.json和代码Data:DefaultConnection:ConnectionString连接字符串.
如何保留代码,并使其在Azure中运行?我尝试在门户中设置应用程序设置,包括连接字符串和应用程序设置.并使用"SQLCONNSTR_DefaultConnection"和"Data:DefaultConnection:ConnectionString"作为键.
(设置应用程序设置似乎不起作用.我认为我提供的值太长).
那么如何在我的Azure Web应用程序(ASP.NET 5)中提供Azure数据库的连接字符串,而不在源代码管理中检入它?
Update My Startup.cs看起来像这样(参见GitHub上的完整文件):
public Startup(IHostingEnvironment env)
{
var configuration = new Configuration()
.AddJsonFile("config.json")
.AddJsonFile($"config.{env.EnvironmentName}.json", optional: true);
if (env.IsEnvironment("Development"))
{
configuration.AddUserSecrets();
}
configuration.AddEnvironmentVariables();
Configuration = configuration;
}
Run Code Online (Sandbox Code Playgroud)
在该ConfigureServices方法中,还有:
services.Configure<AppSettings>(Configuration.GetSubKey("AppSettings"));
Run Code Online (Sandbox Code Playgroud)
而且,在ConfigureServices方法中:
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]))
.AddDbContext<InvoicesDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
// So this is where I want my app in Azure to use the connection string I
// provide in the …Run Code Online (Sandbox Code Playgroud) 我正在使用Autofac,并希望有多个接口实现.如何配置Autofac以便根据当前类型解析依赖关系?
更具体地说,我有一个接口和多个应该链接在一起的实现.
让我解释一下(虚拟课程):
public interface IMessageHandler
{
void Handle(Message message);
}
public class LoggingMessageHandler : IMessageHandler
{
private IMessageHandler _messageHandler;
public LoggingMessageHandler(IMessageHandler messageHandler)
{
_messageHandler = messageHandler;
}
public void Handle(Message message)
{
// log something
_messageHandler.Handle(message);
}
}
public class DoSomethingMessageHandler : IMessageHandler
{
private IMessageHandler _messageHandler;
public DoSomethingMessageHandler (IMessageHandler messageHandler)
{
_messageHandler = messageHandler;
}
public void Handle(Message message)
{
// do something
_messageHandler.Handle(message);
}
}
Run Code Online (Sandbox Code Playgroud)
链的底部可能是一个IMessageHandler不会将消息传递给下一个消息的链接.
如果我想要以下链:
TopLevelClass -> LoggingMessageHandler -> DoSomethingMessageHandler -> FinalHandler
Run Code Online (Sandbox Code Playgroud)
我怎么能告诉Autofac …
我为列表框创建了以下样式,该列表框将在某些文本旁边显示图像:
<Style x:Key="ImageListBoxStyle" TargetType="{x:Type ListBox}">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
<Setter Property="ItemContainerStyle">
<Setter.Value>
<!-- Simple ListBoxItem - This is used for each Item in a ListBox. The item's content is placed in the ContentPresenter -->
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Grid SnapsToDevicePixels="true">
<Border x:Name="Border">
<Grid Height="40">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image
x:Name="DisplayImage"
Source="{Binding Path=ThumbnailImage}"
Height="30" …Run Code Online (Sandbox Code Playgroud) 假设您有以下HTML:
<input />
<br />
<input type=text />
Run Code Online (Sandbox Code Playgroud)
当然,在我的HTML中我也会有其他类型的输入字段(复选框等).现在我只想设置文本输入的样式.
我在搜索时发现的是在CSS中执行以下操作:
input[type=text] { background: red; }
Run Code Online (Sandbox Code Playgroud)
对于第二个输入,显式存在属性,这是有效的.然而,对于第一个,它适用于IE8,但不适用于IE10.也不在Chrome中.
那么我如何定位所有文本输入字段,只有文本输入字段,而不必放在type=text任何地方?
你可以在jsFiddle中看到这个.对于IE8,请查看有关如何使jsFiddle工作的这些说明,但它看起来像这样:

有没有人有将FxCop引入遗留代码的经验?如果有人引入违反规则的代码,我们希望我们的构建失败.但就目前而言,这是不可能的,因为遗留代码有超过9000个违规行为.
抑制我所知错误的唯一方法是通过SuppressMessage属性,但这只适用于方法和GeneratedCodeAttribute.最后一个可以用于类和命名空间(如果我没记错的话),但不应该用于非生成的代码(参见这里).
现在,我们每天花一些时间来删除违规行为,但新的违规行为仍在继续,因为我们的构建不会失败.
有任何想法吗?
考虑以下依赖关系(其中A --> BB意味着A取决于A,因此有效地,A是'父')
A --> B
A --> C
C --> D
C --> E
Run Code Online (Sandbox Code Playgroud)
更加图形化:
A
|
----------
| |
B C
|
-----------
| |
D E
Run Code Online (Sandbox Code Playgroud)
拓扑排序算法将返回如下内容:
ABCDE
Run Code Online (Sandbox Code Playgroud)
我找到了这个代码(展示A和展览B),但都不支持cyclice依赖.我觉得这可能会发生:
A --> B
B --> C
B --> D
C --> B
C --> E
Run Code Online (Sandbox Code Playgroud)
图形:
A
|
B <--> C
| |
D E
Run Code Online (Sandbox Code Playgroud)
这可能会返回ABCDE或ACBDE.因此,因为B和C处于相同的"水平",它们之间的顺序并不重要(同样对于D和E).
我怎么能完成这样的事情.我意识到这不是一个拓扑排序,但我不是专家数学家,所以我真的不知道从哪里开始寻找,更不用说如何实现它了.
就个人而言,我在C#工作,但如果你知道如何用其他任何语言来做,我会很乐意研究你的代码并将其翻译成C#.
更新
我也有以下情况:
A <--------
| |
--> B --> C …Run Code Online (Sandbox Code Playgroud) c# ×3
css ×3
wpf ×2
.net ×1
asp.net-core ×1
autofac ×1
azure ×1
border ×1
combobox ×1
css3 ×1
firefox ×1
foreground ×1
fxcop ×1
html ×1
input ×1
legacy ×1
legacy-code ×1
pseudo-class ×1
sorting ×1
templates ×1