jjzjj

argument-passing

全部标签

c# - OOPS 概念 : What is the difference in passing object reference to interface and creating class object in C#?

我有一个类CustomerNew和一个接口(interface)ICustomer:publicclassCustomerNew:ICustomer{publicvoidA(){MessageBox.Show("Classmethod");}voidICustomer.A(){MessageBox.Show("Interfacemethod");}publicvoidB(){MessageBox.Show("ClassMethod");}}publicinterfaceICustomer{voidA();}我对这两行代码很困惑。ICustomerobjnew=newCustomerNe

c# - 编译器错误 : "error CS0307: The variable ' int' cannot be used with type arguments"

如果我有以下代码:privatevoidCheck(boola,boolb){}privatevoidCheck(inta,intb,intc,boolflag){Check(a(flag?c:b-10));}我在调用Check(int,int)时遇到编译时错误:errorCS0307:Thevariable'int'cannotbeusedwithtypearguments我也遇到了这些错误:errorCS0118:'b'isavariablebutisusedlikeatypeerrorCS0118:'a'isavariablebutisusedlikeatype为什么会出现这些错

c# - DI Framework : how to avoid continually passing injected dependencies up the chain, 且未使用服务定位器(特别是使用 Ninject)

我需要更多帮助才能“了解”像Ninject这样的DI框架如何超越基础知识。以Ninject为例:classSamurai{privateIWeapon_weapon;[Inject]publicSamurai(IWeaponweapon){_weapon=weapon;}publicvoidAttack(stringtarget){_weapon.Hit(target);}}如果没有DI框架(即上面的[Inject]引用),引用类将类似于:classProgram{publicstaticvoidMain(){Samuraiwarrior1=newSamurai(newShuriken

c# - CS1501 : No overload for method 'ToString' takes 0 arguments?

ToString的无重载怎么可能采用零参数?零参数ToString是System.Object的一部分!编辑以回应接近投票:由于我无法将我的构建服务器升级到.NET4.5,有什么方法可以使此代码与.NET4.0/VS2010编译器?没有给我的重载一个完全不同的名称,这并不酷。所讨论的对象是一个F#区分联合,它覆盖了从System.Object继承的ToString方法。被覆盖的ToString正在被属于同一解决方案的C#项目中的代码调用。这一切都很好,直到我将ToString的额外重载添加到我的可区分联合中,它接受一个参数。这一切都在我的本地机器上完美构建和运行(VS2012,所有项目

c# - quartz 调度器 : How to pass custom objects as JobParameter?

我打算编写一个ASP.NET页面来按需触发作业。目前,我正在使用SimpleTrigger类来触发作业,但__Trigger类中没有一个支持对象类型作为JobParameters中的值,据我所知,在钩子(Hook)下使用WCFTcp绑定(bind)将参数传递给作业调度引擎。我想知道如何将自定义对象(可序列化)作为作业参数传递。感谢您的建议! 最佳答案 有两种方法可以传递在Quartz作业执行时可以检索的对象:传递数据映射中的实例。设置作业时,使用如下键将实例添加到map://Createjobetc...varMyClass_myI

c# - 简易喷油器 : Registering a type with constructor argument that's based on its parent

我目前正在从我的项目中删除Ninject,并转而使用SimpleInjector,但有一件事我无法正常工作。对于我的日志记录,在注册服务时,我以前能够将参数传递到我的日志记录类中_kernel.Bind().To().WithConstructorArgument("name",x=>x.Request.ParentContext.Request.Service.FullName);我正在寻找一种在SimpleInjector中重新创建它的方法。到目前为止,除了这个,我还有其他所有工作。通过执行以下操作,我可以使日志记录正常工作,尽管没有显示正确的记录器名称:_container.Re

c# - 通用扩展方法 : Type argument cannot be inferred from the usage

我正在尝试创建一个适用于类型化数据表的通用扩展方法:publicstaticclassExtensions{publicstaticTableTypeDoSomething(thisTableTypetable,paramExpression>[]predicates)whereTableType:TypedTableBasewhereRowType:DataRow{//dosomethingtoeachrowofthetablewheretherowmatchesthepredicatesreturntable;}[STAThread]publicstaticvoidmain(){M

C# : Passing a Generic Object

我想要一个通用的打印函数...PrintGeneric(T)...在下面的例子中,我缺少什么?一如既往地感谢您的帮助/见解...publicinterfaceITest{}publicclassMyClass1:ITest{publicstringmyvar="hello1";}publicclassMyClass2:ITest{publicstringmyvar="hello2";}classDoSomethingClass{staticvoidMain(){MyClass1test1=newMyClass1();MyClass2test2=newMyClass2();Console

传递给函数的 Javascript Find 参数

我需要找到从函数传递给函数的参数。让我们假设我有一个名为foo的函数:functionfoo(){vara=3;varb="hello";varc=[0,4];bar(a-b/c);bar(c*a+b);}functionbar(arg){alert(arg)}当然,就像现在一样,bar将始终警告NaN。在函数bar中,我想以最初传递的形式获取参数。此外,我希望能够从bar函数访问a、b和c的值.换句话说,我想要这种性质的东西:bar(a-b/c);functionbar(){//somemagiccodeherealert(originalArg);//willalert"a-b/c

javascript - 我应该将 jQuery 或 DOM 对象作为参数传递吗? (性能问题)

哪个性能更好。foo(this);functionfoo(element){$(element).index();}或者我应该怎么做foo($(this));functionfoo($element){$element.index();}显然考虑到我将在函数中多次使用该参数。谢谢!康纳 最佳答案 如果无论如何要包装一个对象,那么在jQuery上包装对象的位置并不重要。唯一重要的是您缓存包装结果并且不要将其包装两次。就此而言,以下规则适用于许多插件的代码:1)jQuery变量都以$为前缀:var$this=$(this)2)永远不要在