我有以下一些代码,它们正在触发错误
错误1无效的表达式术语'='
@{
int Interest;
}
<td>@if (@item.interest.HasValue)
{
@Interest= @item.interest.Value.ToString("F2");
}
Run Code Online (Sandbox Code Playgroud) 我在Windows窗体上有一个DatagridView控件.它的selectionMode属性设置为CellSelect.
我想基于选定的单元格操作DatagridViewRow.DataGridView控件绑定到DataSource.
如何根据选定的单元格获取Row集合?
在回答另一个问题时,Jon Skeet提到有一个奇怪的事情正在进行定义enums.他的回答.
他声明,enum只有类型别名而不是框架类型(int有效,Int32不是等)才能重新定义a的基础类型.
public enum Foo : UInt32 {} // Invalid
public enum Bar : uint {} // Valid
Run Code Online (Sandbox Code Playgroud)
现在我试图重现(在VS2015中使用C#6/Roslyn),我没有得出相同的结论:
public enum TestEnum : UInt32
{
}
Run Code Online (Sandbox Code Playgroud)
和
public enum MyEnum : uint
{
}
Run Code Online (Sandbox Code Playgroud)
都是完全有效的.为什么会这样?或者改变了什么?
编辑:
所以为了清理事情,这是C#6中的一个变化,尚未记录,并且很快就会记录下来,因为你可以从Roslyn Github上的这个git问题中读到
所以我在网上看了一个视频,向我展示了如何在WPF应用程序中实现MVVM.请注意,对于他们两个人来说,我是新手.
我有以下类,包括我的WPF应用程序的Model,View和ViewModel层:
基本上我只有两个视图(故障和部件)被加载到MainWindow视图中.
我现在已经设置好了,因此我可以在代码中输入和显示代码以显示MainWindow中的MalfunctionView或PartsView.例如,如果我想看到MalfunctionView,那么我会注释掉所有的PartsView代码,然后在VS中重新运行它.是的,我知道......这是悲伤和可怜的,但我还没有学会如何卸载一个视图并在飞行中加载另一个视图.这让我想到了一个问题:如何从MainWindow卸载一个视图,然后将另一个视图加载到MainWindow中?例如,我在PartsView上有一个名为Select的按钮,当点击它时,需要从MainWindow卸载PartsView并在其中加载MalfunctionsView.
我包含了我为App类和MainWindow View和MainWindow ViewModel编写的代码,以便可以看到我当前如何将ViewModel(用户控件)加载到MainWindow中.
App.xaml.cs
public partial class App : Application {
protected override void OnStartup(StartupEventArgs e) {
base.OnStartup(e);
// Create MainWindow ViewModel
var mainWindowVM = new MainWindowVM();
// Create MainWindow View
MainWindow mainWindowVw = new MainWindow();
// Set MainWindow View datacontext to MainWindow ViewModel and then show the window
mainWindowVw.DataContext = mainWindowVM;
mainWindowVw.Show();
}
}
Run Code Online (Sandbox Code Playgroud)
MainWindow.xaml
<Window x:Class="PAM.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:PAM.ViewModel"
xmlns:vw="clr-namespace:PAM.View"
Title="Parts and Malfunctions" …Run Code Online (Sandbox Code Playgroud) 我想初始化一个新的int数组.
有什么好处:
var myNewArray = new int[]{};
Run Code Online (Sandbox Code Playgroud)
和:
var myNewArray = new int[0];
Run Code Online (Sandbox Code Playgroud)
我应该优先选择哪一个,还是仅仅是代码风格的问题?
我正在阅读C# Cookbook 中的并发,这本书告诉我:
ConcurrentDictionary<TKey, TValue>当您有多个线程读取和写入共享集合时,这是最好的。如果更新不是恒定的(如果它们更罕见),那么这ImmutableDictionary<TKey,TValue>可能是一个更好的选择。
我知道 Add or Remove a large immutable collection 可能很慢,我的问题是,它们之间还有其他区别吗?既然它们都是线程安全的,那么ImmutableDictionary当更新不是恒定的时,为什么是更好的选择呢?
我有一个带有泛型的抽象基类,我将针对这个问题简化它:
public abstract class DBBaseTable<T>
{
public T Id { get; set; }
public byte[] RowVersion { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
现在,我可以有这样的课程:Person : DBBaseTable<int>或Animal: DBBaseTable<Guid>
我试图避免反射,以便在我根本不知道T类型的代码的一部分中访问属性 RowVersion 。
var memberInfo = oldObject.GetType().BaseType;
if (memberInfo != null
&& memberInfo.IsGenericType
&& memberInfo.GetGenericTypeDefinition() == typeof(DBBaseTable<>)
)
{
var isCorrectRowVersion = (oldObject as DBBaseTable<object>).RowVersion ==
(objToUpdate as DBBaseTable<object>).RowVersion;
//TODO....
}
Run Code Online (Sandbox Code Playgroud)
条件 IF 条件工作正常......但是当我尝试使用as运算符时,我总是需要指定T类型......我尝试使用“对象”但它不起作用......我根本不知道我是在处理 int、guid 还是其他类型的......
我知道如何通过反射解决这个问题,但我想知道是否有替代方案?
我正在使用以下结构:
(层)“基础层”->(子状态)“ Jump_Fall_Roll”->(状态)“ Roll”
static int rollState = Animator.StringToHash("What to put here??");
private Animator anim;
private AnimatorStateInfo currentBaseState;
void Start ()
{
anim = GetComponent<Animator>();
}
void FixedUpdate ()
{
currentBaseState = anim.GetCurrentAnimatorStateInfo(0);
if (currentBaseState.nameHash == rollState) {
Debug.Log ("ROLL nameHash worked"); //Not working
}
if (currentBaseState.IsName("Roll")) {
Debug.Log ("ROLL IsName worked"); //Working.......
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试了每个可能的父母/州的组合来使用nameHash,但从未成功过……
名称应采用Layer.Name形式,例如“ Base.Idle”。
来自Unity的AnimatorStateInfo.IsName文档
那么,为什么我的第一个案例不起作用?第二种情况如何工作?
我真的很困惑
编辑
我的Animator视图的屏幕截图

我确实尝试过 static int rollState = Animator.StringToHash("Base Layer.Roll");
然后 Debug.Log (currentBaseState.nameHash + ", " + rollState);
将输出
1094782407,-1476868190 …
当我执行我的查询时:
rs.Select(x => x.id).ToArray();
Run Code Online (Sandbox Code Playgroud)
我得到了这个错误:
LINQ to Entities不支持LINQ表达式节点类型"Invoke"
这是生成错误的方法(可能是func(x)):
public IQueryable<TEntity> Compare<TEntity>(IQueryable<TEntity> source, Func<TEntity, int> func)
{
IQueryable<TEntity> res = source;
if (!this.LBoundIsNull) res = res.Where(x => func(x) >= _lBound);
if (!this.UBoundIsNull) res = res.Where(x => func(x) <= _uBound);
return res;
}
Run Code Online (Sandbox Code Playgroud)
我在这种模式下调用方法:
Document doc = new Document();
doc.Number = new RangeValues(lBound, null);
using (MyEntities db = new MyEntities())
{
var rs = db.documents;
if (doc.Number != null) rs = doc.Numero.Compare(rs, x => x.number);
long[] id = rs.Select(x …Run Code Online (Sandbox Code Playgroud) 我试图从Type变量中获取一个类型.例如:
Type t = typeof(String);
var result = SomeGenericMethod<t>();
Run Code Online (Sandbox Code Playgroud)
第二行发生错误,因为t不是a type,它是变量.有什么办法让它成为一种类型?