我有以下Razor代码部分,它在运行时因编译错误而失败:
@foreach(var stat in Model){
<li>
@stat.EffectiveDate.ToShortDateString() - @stat.EventType.Description <br />
TimeTaken:
@if (@stat.TimeTaken.Hours > 0) {
@stat.TimeTaken.Hours hours
}
@stat.TimeTaken.Minutes minutes
@stat.TimeTaken.Seconds seconds.
</li>
}
Run Code Online (Sandbox Code Playgroud)
错误就@stat.TimeTaken.Hours hours
行了
CS1002 :; 预期
删除文字hours
修复它.
我很困惑.
编辑:这是从"@if"到"秒"的编译输出.
Line 180: if (@stat.TimeTaken.Hours > 0) {
Line 181:
Line 182:
Line 183: #line default
Line 184: #line hidden
Line 185:
Line 186: #line 29 "c:\documents and settings\dave\my documents\visual studio 2010\Projects\SportStats\SportStats\Views\Stats\Index.cshtml"
Line 187: this.Write(stat.TimeTaken.Hours);
Line 188:
Line 189: #line default
Line 190: …
Run Code Online (Sandbox Code Playgroud) 我总是对这些东西感到困惑.
我有这个问题:
string[] names = { "Tom", "Dick", "Harry", "Mary", "Jay" };
IEnumerable<string> query = names.Where(n => n.Contains("a"))
.OrderBy(n => n.Length)
.Select(n => n.ToUpper());
Run Code Online (Sandbox Code Playgroud)
我在一本书中读过:
编译器通过将查询表达式转换为流畅语法来处理查询表达式
但在Reflector我看到相反的情况:
这不是流利的语法.
那么编译器看到了什么?
我收到错误消息:
System.Windows.Data错误:4:找不到参考'ElementName = gridProductViewDataGrid'的绑定源。BindingExpression:Path = SelectedItem; DataItem = null; 目标元素是'MenuItem'(Name =''); 目标属性为“ IsEnabled”(类型为“布尔”)
在Visual Studio的“输出”窗口中,我的代码没有执行应做的事情。
该添加工作正常,因为它不需要禁用,但不禁用删除。
<DataGrid AutoGenerateColumns="False" IsReadOnly="False" CanUserAddRows="False" CanUserDeleteRows="False" EnableRowVirtualization="True" ItemsSource="{Binding Items, Mode=TwoWay}" x:Name="gridViewProductDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" >
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="{Binding LabelStrings.AddProductLabel, Source={StaticResource ResourceWrapper}}" Click="Add_Product_MenuItem_Click"/>
<MenuItem Header="{Binding LabelStrings.RemoveProductLabel, Source={StaticResource ResourceWrapper}}" Click="Remove_Product_MenuItem_Click" IsEnabled="{Binding ElementName=gridViewProductDataGrid, Path=SelectedItem, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource ObjectToBooleanConverter}}"/>
</MenuItem>
</ContextMenu>
</DataGrid.ContextMenu>
Run Code Online (Sandbox Code Playgroud)
如果没有对象,转换器将简单地返回true,如果存在则返回false。我试过将此代码移入和移出网格,以及按不同顺序移动绑定的各个部分。当我运行代码并将其置于断点时,它从未进入过布尔转换器的代码。为什么在网格内部时看不到网格?
我在TFS中遇到文件冲突,无法解决:
如果单击“ 自动解决”,它将显示:
由于内容更改,名称更改或编码更改存在冲突,因此尚未解决任何冲突。这些冲突将需要单独解决
但这并没有给我任何合并选项。
我尝试取消映射并从磁盘删除工作空间并重新添加它,但是冲突仍然存在。有什么想法如何摆脱它吗?
编辑,问题似乎是由文件名称更改引起的。与错误消息中的文件相比,磁盘上的文件缺少字母。
我如何迭代引用类型(例如MyClass)并获取其中一个字段的值(值类型)
我用下一个代码.
.foreach (address {!DumpHeap -type MyClass -short }) {!do ${address} (what I do next?) }
Run Code Online (Sandbox Code Playgroud)
我得到了对象的转储,但是如何获取所有对象的字段值?
我正在尝试使用以下xml填充数组:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<data>
<item>
<date>1307018090</date>
<price>10.4718867</price>
<low>10.38100000</low>
<high>10.49000000</high>
<nicedate>14:39</nicedate>
</item>
<item>
...
</item>
Run Code Online (Sandbox Code Playgroud)
等等
我正在使用这个Linq查询,对我来说意味着它将创建一个对象:
var items = from item in doc.Element("data").Descendants()
select new Currency
{
Close = item.Element("price").Value.ToString(),
Date = item.Element("date").Value.ToString(),
Low = item.Element("low").Value.ToString(),
High = item.Element("high").Value.ToString(),
Time = item.Element("nicedate").Value.ToString()
};
Run Code Online (Sandbox Code Playgroud)
当我通过项目进行预测时,只选择一个项目.我不太习惯Linq,所以我无法弄清楚如何正确构建这个语句.有什么建议?
有人可以解释一下我在这里缺少什么.基于我的基本理解,将在使用结果时计算linq结果,我可以在下面的代码中看到.
static void Main(string[] args)
{
Action<IEnumerable<int>> print = (x) =>
{
foreach (int i in x)
{
Console.WriteLine(i);
}
};
int[] arr = { 1, 2, 3, 4, 5 };
int cutoff = 1;
IEnumerable<int> result = arr.Where(x => x < cutoff);
Console.WriteLine("First Print");
cutoff = 3;
print(result);
Console.WriteLine("Second Print");
cutoff = 4;
print(result);
Console.Read();
}
Run Code Online (Sandbox Code Playgroud)
输出:
First Print 1 2 Second Print 1 2 3
现在我改变了
arr.Where(x => x < cutoff);
Run Code Online (Sandbox Code Playgroud)
至
IEnumerable<int> result = arr.Take(cutoff);
Run Code Online (Sandbox Code Playgroud)
输出如下.
First …
在将其提交给TFS之前,我想强制我的所有团队成员对他们的C#源代码执行代码分析.在此分析中,我希望具有代码质量(样式和可能的错误).
我找到了CodeRush,ReSharper,但它们非常昂贵.我也发现了FXCop,但它只适用于DLL和EXE文件.我喜欢StyleCop,但我找不到将它集成到TFS的方法,并且警告消息中没有"严重性".
你知道有这种功能的工具吗?
谢谢!
我需要从给定的到达和旅行时间计算发射时间.我已经研究过DateTime,但我不太确定我会怎么做.我使用monthCalander以下面的格式获取到达dateTime.
Example:
Arrival_time = 20/03/2013 09:00:00
Travel_time = 00:30:00
Launch_time = Arrival_time - Travel_time
Launch_time should equal: 20/03/2013 08:30:00
Run Code Online (Sandbox Code Playgroud)
有人能告诉我一个简单的方法来实现这一点.非常感谢.
我正在使用Visual Studio 2013和SQL Server 2012在C#中开发.我已经能够使用T-SQL在地理列中存储多边形,并且我没有尝试在代码中使用SqlGeography类来检索数据.
当我尝试:
SqlGeography polyB = (SqlGeography)dr["extent"]; // stored in OGC Well Known Binary format
Run Code Online (Sandbox Code Playgroud)
从数据库中检索多边形我收到的消息:
GeoLib.dll中发生了未处理的"System.InvalidCastException"类型异常
附加信息:[A] Microsoft.SqlServer.Types.SqlGeography无法强制转换为[B] Microsoft.SqlServer.Types.SqlGeography.类型A源自'Microsoft.SqlServer.Types,Version = 10.0.0.0,Culture = neutral,PublicKeyToken = 89845dcd8080cc91',位于'默认'位置'C:\ Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Types\10.0 .0.0__89845dcd8080cc91\Microsoft.SqlServer.Types.dll".
类型B源自'Microsoft.SqlServer.Types,Version = 11.0.0.0,Culture = neutral,PublicKeyToken = 89845dcd8080cc91',位于'默认'位置'C:\ Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Types\11.0 .0.0__89845dcd8080cc91\Microsoft.SqlServer.Types.dll".
我怀疑SQL Server和Visual Studio之间的版本不兼容,如不同的版本号所示.有没有人碰到这个?也许我需要安装SQL Server 2014?任何想法都表示赞赏!
c# ×9
linq ×3
tfs ×2
.net-4.0 ×1
asp.net-mvc ×1
azure-devops ×1
datetime ×1
linq-to-xml ×1
razor ×1
sql-server ×1
sqlgeography ×1
windbg ×1
wpf ×1
xaml ×1
xml ×1
xml-parsing ×1