【c#-将类的列表传递给方法,并将抽象基类的列表作为参数】教程文章相关的互联网学习教程文章

c# – 使用Lambda捕获参数【代码】

当我尝试捕获函数的参数时,C#编译器生成了什么代码?partial class NewClass : Window {public NewClass(){InitializeComponent();new Thread(Work).Start();}void Work(){Thread.Sleep(5000); // Simulate time-consuming taskUpdateMessage("The answer");}void UpdateMessage(string message){Action action = () => txtMessage.Text = message;Dispatcher.BeginInvoke(action);} }我知道lambdas可以在创建新类之后在其词法范围...

C#String.Format可选参数【代码】

我想使用带有可选参数的string.Format:public static void Main(string[] args) {// Your code goes here// Console.WriteLine(string.Format("{0} {1}", "a", "b"));Console.WriteLine(string.Format("{0} {1}", "a")); }例如,参数{1}是可选的并具有默认值 你能帮帮我吗?解决方法:这取决于“可选参数”的含义. 如果要使用默认值自动替换null,最简单的方法是在参数内使用null coalescing运算符:String.Format("{0} {1}", "a",so...

c# – ArgumentNullException:值不能为null.参数名称:构造函数【代码】

我正在使用EF 7构建一个ASP.NET 5 MVC应用程序.我有三个型号:书类:public class Book : IBook<MangaChapter>, IHasThumbnail, IBugChecker{public Book(){Chapters = new List<MangaChapter>();}[Key]public int ID { get; set; }[Required]public string Title { get; set; }[Required][DataType(DataType.MultilineText)]public string Description { get; set; }public string ThumbnailPath { get; set; }public virtual ILi...

c# – 为什么我对Kairos api的REST请求说请求缺少必需的参数?【代码】

我正在尝试连接到kairos api以熟悉它并使用它们的检测功能. 这个api还没有正式的C#库.有一个似乎没有积极维护. 我正在尝试使用RestSharp直接连接.服务器正在接收我的请求,如果我省略app_id和app密钥进行身份验证,就会响应我的预期.所以那部分(添加标题)似乎正在起作用. 添加参数似乎失败了.根据他们的网站:https://www.kairos.com/docs/face-recognition/,唯一需要的参数是带有网址或base64编码照片的“图片”. 我添加了参数:va...

c# – 使用angular post将两个参数传递给WEB API调用【代码】

我的WEB API控制器中有以下post方法:public async Task<HttpResponseMessage> SendPost(Application application)我使用angular.js $http.post通过javascript调用它,并将应用程序参数作为JSON传递:$http.post("/api/AController/SendPost", JSON.stringify(application)).success(function (data, status, headers, config) { }这有效. 现在我想将第二个参数作为一个简单的字符串传递(我不能修改现有的应用程序JSON对象).我尝试了...

c# – 是否可以在url中操作之前定义参数【代码】

问题就像标题一样简单. 是否可以使用如下所示的路线:{controller} / {id} / {action}? 这就是我现在的代码(只是一个简单的函数)(设备是我的控制器):[HttpGet] [Route("Device/{id}/IsValid")] public bool IsValid(int id) {return true; }但是,当我转到以下URL时,浏览器说它找不到页面:localhost / device / 2 / IsValid. 当我尝试这个URL时,它可以正常工作:localhost / device / IsValid / 2 那么,是否可以使用localhost / ...

c# – 类型’Startup’已经定义了一个名为’Configuration’的成员,它具有相同的参数类型【代码】

我在我的startup.cs上有这个using Microsoft.Owin; using Owin;[assembly: OwinStartupAttribute(typeof(xx.yy.Startup))] namespace xx.yy {public partial class Startup{public void Configuration(IAppBuilder app){ConfigureAuth(app);}} }我有这个Startup.Auth.csusing System; using Microsoft.Owin; using Microsoft.Owin.Security.Cookies; using Owin;namespace xx.yy {public static class xxAuthentication{public con...

c# – 替换lambda表达式中的参数类型【代码】

我试图将lambda表达式中的参数类型从一种类型替换为另一种类型. 我在stackoverflow上找到了其他答案,即this one,但我没有运气. 想象一下你有一个域对象和一个存储库,你可以从中检索域对象. 但是,存储库必须处理自己的数据传输对象,然后映射并返回域对象: ColourDto.cs public class DtoColour {public DtoColour(string name){Name = name;}public string Name { get; set; } }DomainColour.cs public class DomainColour {public...

c# – 404传递web api参数时【代码】

我正在尝试使用此方法:public class DocumentenController : ApiController { [HttpPost][Route("DeleteDocument/{name}/{planId}")]public IHttpActionResult DeleteDocument(string name, int planId){_documentenProvider.DeleteDocument(planId, name);return Ok();} }这是WebApiConfig:config.MapHttpAttributeRoutes();config.Routes.MapHttpRoute(name: "ActionApi",routeTemplate: UrlPrefix + "/{controller}/{actio...

c# – 将多个对象作为参数传递给mvc 6动作【代码】

我有一个工作正常的MVC 5项目,我需要将该项目迁移到带有.NET核心的MVC 6.在设法调整所有工作之后,我遇到了一个问题:我的许多操作都接受了多个对象作为参数.模型绑定器MVC 5正在使用没有问题,但MVC 6似乎在这些操作的所有参数中都置零,我想这是MVC和WebAPI统一的一部分.我的问题是,如果它周围没有添加另一个请求包装器对象的模型库.例如:[HttpPost]public ActionResult GetVersionData(OvlEnvironment environment, Pipeline pipe...

c# – 首先通过将type作为参数传递,在Entity Framework DB中动态实例化Model对象【代码】

需要通过将表名作为参数(在DB第一种方法中生成的模型并使用EF 6.0)动态创建实体框架生成的Model类的实例 喜欢,// Input Param string tableName // Context always same DBContext dbContext= new DBContext(); //Need to create object query dynamically by passing //table name from front end as below IQueryable<"tableName"> query = dbContext."tableName ";需要传递100个表作为输入参数并且所有表的结构相同. 请帮忙.解...

c# – 必须使用适当的属性或方法修改“Content-Type”标头.参数名称:名称【代码】

您好我使用HttpWebRequest GET方法来调用REST服务.我收到错误: – ***’Content-Type’标头必须使用适当的属性或方法进行修改.参数名称:name.***我从stackoverflow检查了所有与此问题相关的答案. 我的代码: – using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;public partial class _Defaul...

c# – ex = {“AADSTS70002:请求正文必须包含以下参数:’client_secret或client_assertion’【代码】

这就是我编写代码并尝试获取输出的方法.The request body must contain the following parameter: client_secret or client_assertionstatic async Task<AuthenticationResult> getAccessToken(){string hardcodedUsername = "";string hardcodedPassword = "";string tenantName = "projectwidgets.com";string authString = "https://login.microsoftonline.com/" + tenantName;AuthenticationContext authenticationContext = n...

c# – Ajax.BeginForm,有4个参数没有找到action方法【代码】

我有一个奇怪的案例,我想要你的启蒙.我有两个控制器.一般人员控制器使用行动方法和一个候选人控制器,用于与候选人相关的更具体的行动方法.我使用位于Person文件夹下的一个局部视图,以便在以后我想将其用于其他类型的Person时用作通用.目前,此局部视图使用针对候选控制器的Ajax.BeginForm.我正在使用的语法是@using (Ajax.BeginForm("SaveCandidateLanguage", "Candidate",new AjaxOptions{HttpMethod = "Post",OnBegin = "onBeginF...

如何在c#中将数组作为查询字符串的参数发送?【代码】

我正在尝试使用自行开发的Web API来检索一些数据.文档全部用PHP编写.我正在看的例子是这样的:$params = array('id' => 1,'data' => array(,'email' => 'example@hasoffers.com')$url = "www.someapi.com/api?" . http_build_query( $params );我正在使用C#WebClient类,但我无法弄清楚如何序列化数据参数:WebClient wc = new WebClient(); wc.QueryString["id"] = "1"; wc.QueryString["data"] = // I have no idea.string json =...