【c# – 是否可以在url中操作之前定义参数】教程文章相关的互联网学习教程文章

c#-在MVVM中绑定事件并将事件参数作为命令参数传递【代码】

我想用ViewModel绑定一个事件. 我用了clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity和我使用触发器相同<Canvas Grid.Row="2" Grid.Column="2" x:Name="InteractiveCanvas" Style="{StaticResource canvasChartStyle}" ClipToBounds="True" ><intr:Interaction.Triggers><intr:EventTrigger EventName="MouseEnter"><intr:InvokeCommandAction Command="AppointmentEditing" /></intr:EventTr...

C#-Enum参数的DefaultValue和RawDefaultValue的意外差异【代码】

考虑以下示例:class Program {static void Main(string[] args){foreach(var par in typeof(A).GetMethod("Method").GetParameters()){Console.WriteLine("Def {0}, RawDef {1}",par.DefaultValue, par.RawDefaultValue);}} }class A {public void Method(int a = 5, B b = B.b){} } enum B {a = 0, b = 1 }根据RawDefaultValue和DefaultValue的文档,以及StackOverflow的支持,这两种访问默认值的方法应返回相同的数据. 但是,我得到...

c#-在我的后端使用[FromBody]识别WebAPI参数是一种好习惯吗?【代码】

我有一个用angular和TypeScript编写的前端WebAPI,看起来像这样.removeSubset(id: number): ng.IPromise<any> {return this.$http.post(this.api + '/DeleteStudySubset', id).then(this.returnData);}returnData = (response: any) => {return response.data;};它调用的后端版本是这样写的[HttpPost][ResponseType(typeof(IHttpActionResult))]public async Task<IHttpActionResult> DeleteStudySubset(int id){await _subsetRepo....

虚方法和重写方法中的c#可选参数【代码】

我注意到使用具有可选参数的虚拟方法时.当您覆盖此方法并为可选参数使用其他默认值时,它将使用原始值.对我来说似乎有点奇怪.static void Main(string[] args) {List<Piece> Pieces = new List<Piece>();Pieces.Add(new Piece());Pieces.Add(new Pawn());foreach(var v in Pieces){Console.WriteLine(v.getPos());}Console.ReadKey(); }class Piece {public virtual long getPos(bool enPassant = false){if (enPassant)return 2;re...

C#-参数化多行插入【代码】

有什么方法可以参数化插入多行的SQL INSERT语句(在C#中)?目前,我只能想到一种方法来生成用于插入多行的语句,但这对于SQL注入是相当开放的:string sql = " INSERT INTO my_table"+ " (a, b, c)"+ " VALUES";// Add each row of values to the statement foreach (var item in collection) {sql = sql+ String.Format(" ({0}, {1}, {2}),",aVal, bVal, cVal); }// Remove the excessive comma sql = sql.Remove(sql.Length - 1);什...

C#将所有对象参数复制到子类对象【代码】

假设我有一个不能更改的父类的对象-例如,带有长参数列表的ListBox实例.现在,我创建一个子类:class PlaylistBox : ListBox {void CopySettingsFrom(ListBox In){//...what now?} }问题-如何有效地从In对象向PlaylistBox的新对象进行浅表复制?解决方法:这是一个基于反射和AutoMapper的具有3种方法的示例,并带有说明:internal class Program{private static void Main(string[] args){Example1();Example2();Example3();}public st...

c#-将对象动态列表作为参数传递【代码】

我有一种方法,可以通过以下方法传递对象列表:public void BindGridView(int pageIndex, List<Users> lstUsers, GridView grd, Panel pl) {}参见上面的列表List< Users>.是固定的,因此我可以在方法中静态传递它.我将使用相同的方法在网格中显示数据并计划在存在其他对象列表时动态传递.以上述方式,我必须声明所有列表,如下所示:public void BindGridView(int pageIndex, List<Groups> lstGroups, GridView grd, Panel pl) { }publ...

c#-将类的列表传递给方法,并将抽象基类的列表作为参数【代码】

我有从抽象基类继承的类,并且我想将任何这些类的列表传递到以基类列表为参数的方法中.我该如何实现? 这是我想尝试的-public abstract class MyBaseClass {}public class MyClass1 : MyBaseClass {}//Inside another class public void MyMethod(List<MyBaseClass> listOfBaseClass){}//Inside another class List<MyClass1> myClass1List = new List<MyClass1>(); MyMethod(myClass1List); //ERROR HERE, This method call does n...

API正常运行,但参数不接受C#【代码】

我在这里有我的路线前缀:[RoutePrefix("api/Adresses")] public class AdressesController : ApiController {我的功能在这里:[Route("{codeEtudiant}")] // GET: api/Adresses/1 public IEnumerable<Object> getAdresseEtu(Int32 code) {我在哪里调用我的api:using (var client2 = new HttpClient()) {string getasync = "http://localhost:11144/api/Adresses/" + etu.Code;var response2 = await client.GetAsync(getasync);v...

c#-生成仅通过转发参数来调用类私有字段方法的方法?【代码】

在Visual Studio或ReSharper中是否可以生成仅将参数转发到私有字段的方法的方法?class Inner {public void Test(String a, String b){} } class Outer {private Inner _inner;public Outer(Inner inner){_inner = inner;}/*//I want to generate this:public void Test(String a, String b){_inner.Test(a, b);}*/ }解决方法:您正在寻找的Resharper功能称为“生成委派成员”,其描述为here:To generate delegating membersIn the ...

c#-错误“参数声明为in时参数是值”是什么意思?【代码】

在netstandard 2.0应用程序中,我具有以下属于静态类的方法:public static class Argument { /// <param name="inst">Inst.</param>/// <param name="instName">Inst name.</param>/// <exception cref="ArgumentException">/// Thrown if :/// <paramref name="inst" /> is not specified in a local time zone./// </exception>public static void ThrowIfIsNotLocal(in DateTime inst, string instName){if (inst.Kind != D...

c#-以存储过程为参数调用函数【代码】

我在C#中具有以下功能正常工作private void AddQueue() {SqlConnection conn = forconnection();conn.Open();SqlCommand cmd = new SqlCommand("spInsertFormIssue",conn);cmd.CommandType = CommandType.StoredProcedure;cmd.Parameters.Add("@Qdatetime", SqlDbType.DateTime).Value = DateTime.Now;cmd.ExecuteNonQuery();conn.Close(); }现在,我想要相同的功能,但具有不同的存储过程,我想将此功能与另一个存储过程一...

c#-当将lambda作为参数传递但不直接使用时,’LINQ to Entities不支持LINQ表达式节点类型’Invoke’【代码】

在有人投票关闭this、this和许多其他类似问题的副本之前,请仔细阅读该问题,因为我认为不是(即使看起来非常相似). 我有一个Linq查询,如下所示…List<int> ids = ctx.Where(a => a.PartInformationTypeID == pitID && vals.Contains(a.PartDefinitionID)).Select(a => a.SystemID).Distinct().ToList();…其中pitID是一个i??nt值,而vals是一个List< int> 这很好用,但是由于我有四个这样的查询,只是在Where子句中的lambda不同而已,我认...

c#-.net webApi中不带id参数的删除请求【代码】

我有如下的.net核心WebApi.而且它运行良好.但是,当我写[HttpDelete]而不是[HttpDelete(“ {id}”)]时,它不起作用.可能是什么原因? 我的网址:http://localhost:5004/api/Student/DeleteStudent/23[ApiController] [Route("api/[controller]/[action]")] public class StudentController : ControllerBase {//[HttpDelete] ///////////////// This is not working[HttpDelete("{id}")] /////////// This is workingpublic async Ta...

c#-传递引用参数与包装类型的详细列表【代码】

我需要从一个函数中获取三个对象,我的本能是创建一个新类型来返回三个引用.或者如果ref是相同的类型,我可以使用数组.但是,通过引用比较容易:private void Mutate_AddNode_GetGenes(ref NeuronGene newNeuronGene, ref ConnectionGene newConnectionGene1, ref ConnectionGene newConnectionGene2){}显然这没有什么错,但是我不愿使用这种方法,主要是出于美学和心理偏见的考虑.实际上,是否有充分的理由使用其中一种方法来替代其他方...