我在不同的网站中漫游以进行投射技术,我构建了以下代码以从中float
转换int
为如下所示
var floatList = new float[] { 2.7f, 3.1f, 4.5f };
var intList = from int test1 in floatList
select test1;
foreach (var v in intList)
Console.Write("{0} ", v.ToString());
Run Code Online (Sandbox Code Playgroud)
但是上面的代码抛出了一个InvalidCastException
.为什么是这样?我以为它应该打印3,3
和4
.
我最近开始使用TDD,或者你可以说测试我的项目,在那里我找到了一些新东西(对我来说是新的东西),称为"代码覆盖率",它显示了在测试过程中你的代码覆盖了多少.而且我知道大多数老年人都会说它不可能拥有100%的代码覆盖率或者不是很好的做法来获得100%的代码覆盖率.这件事让我想知道这个代码覆盖如何工作我的意思是他们涵盖了哪些基础的代码?请告诉我们测试的主要用法.
我附上了这个问题的代码覆盖图像.
我正在尝试使用 Material 在 Angular 中实现多选。
当页面在编辑模式下打开时,某些类型应该在多选中选择为默认值,但在我的情况下不起作用。
下面是 HTML:
<mat-form-field >
<mat-select placeholder="DocTypes" [(value)]="selectedDocType" formControlName="docTypes" multiple>
<mat-option *ngFor="let doc of docs" [value]="doc.name">{{doc.name}}</mat-option>
</mat-select>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
我正在填写 SelectedDocType 如下:
selectedDocType: string[] = new Array();
resp.forEach(x => {
this.selectedDocType.push(x.name);
});
Run Code Online (Sandbox Code Playgroud)
这里 resp 包含正确的文档类型。比如简历。
奇怪的是,当我将 selectedDocType 设置为如下所示时,它就可以工作了:
this.selectedDocType = ["CV"];
Run Code Online (Sandbox Code Playgroud)
但是当我按上面提到的 for each 时,它不起作用。他们两个在数组中都有 1 个值。
我究竟做错了什么?
更新:文档格式如下:
export interface DocTypes{
id: string;
name: string;
}
Run Code Online (Sandbox Code Playgroud) 我的代码中出现以下错误:
'L'运算符后缺少操作数.
我调试了代码,发现它发生在下面的行:
DataRow[] documents = this.DataSet.Results_Documents.Select(String.Format("DocumentControlNumber = '{0}'", dcn), null, DataViewRowState.CurrentRows);
Run Code Online (Sandbox Code Playgroud)
这是当dcn包含'
在其完整字符串中时发生的.
这是什么原因?
例如:dcn: - 谢尔顿的Nat'l Bk
如何在mvc中启用角色?我的代码在下面给出,我不知道如何创建角色,我想将其添加到数据库..
[AttributeUsage(AttributeTargets.All)]
public class UserRightAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
//write your user right logic
//if user has right to do nothig otherwise redirect to error page.
string message = "It seems You are not authorize to view this part of the web site!!!.";
RouteValueDictionary redirectTargetDictionary = new RouteValueDictionary();
redirectTargetDictionary.Add("area", "");
redirectTargetDictionary.Add("action", "SaveData");
redirectTargetDictionary.Add("controller", "Home");
redirectTargetDictionary.Add("customMessage", message);
filterContext.Result = new RedirectToRouteResult(redirectTargetDictionary);
}
}
Run Code Online (Sandbox Code Playgroud) c# authentication model-view-controller asp.net-mvc authorization