草庐IT

method-group

全部标签

c# - 为什么 Property 执行比 Field 或 Method 执行慢?

在CLRviaCSharp第10章“属性”JeffRichter写道:Apropertymethodcantakealongtimetoexecute;fieldaccessalwayscompletesimmediately.Acommonreasontousepropertiesistoperformthreadsynchroni-zation,whichcanstopthethreadforever,andtherefore,apropertyshouldnotbeusedifthreadsynchronizationisrequired.Inthatsituation,ameth

c# - 计划的 Azure WebJob 但未调用 NoAutomaticTrigger-Method

这个问题与这个问题相关:RunningAzureWebJobwithoutqueue我的场景:我只想每小时将一个文件写入blob存储,不需要任何队列系统。从前一个问题中,我得到了这段代码——它在第一次被触发时运行良好:[NoAutomaticTrigger]publicstaticvoidDoWork([Blob("container/foobar.txt")]TextWriterwriter){writer.Write("HelloWorld"+DateTime.Now.ToShortTimeString())"}staticvoidMain(){JobHosthost=newJob

c# - 系统.Runtime.Serialization.InvalidDataContractException : No set method for property

如错误所示,我的属性没有setter,但我不想要setter,它应该是只读的。 最佳答案 已编辑:使二传手成为内部。这仍然可以在程序集中设置,但这是一个很好的技巧,当用于位于其他人使用的程序集中的数据对象时效果很好,因为那些使用程序集的人将无法设置该属性,但是各种序列化程序都可以。 关于c#-系统.Runtime.Serialization.InvalidDataContractException:Nosetmethodforproperty,我们在StackOverflow上找到一个类

c# - C++/命令行界面 : How do I declare abstract (in C#) class and method in C++/CLI?

以下C#代码在C++/CLI中的等价物是什么?publicabstractclassSomeClass{publicabstractStringSomeMethod();} 最佳答案 只需稍微混合关键字即可获得正确的语法。abstract在C#中位于前面,但在C++/CLI中位于末尾。与override关键字相同,今天也被C++11兼容的编译器识别,它们期望它位于函数声明的末尾。就像传统C++中的=0标记函数抽象一样:publicrefclassSomeClassabstract{public:virtualString^SomeM

c# - 为什么这个程序会出错? `Object synchronization method was called from an unsynchronized block of code`

这段代码有什么问题?我收到“从未同步的代码块调用对象同步方法”。我在谷歌上发现了一个结果,说我可能在锁定之前释放了一个互斥体,但根据我的输出,情况并非如此。这是互斥锁代码,中间没有其他代码。-edit-对不起大家,贴错了。我的输出1W1W2W代码usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Threading;namespacesqliteTest{classProgram{staticvolatileMutexmut1=newMutex();staticvolatileMutexmut

c# - 数字必杀技 : Where does a callvirt of a non-existent method end up?

我在其基类中标记为抽象的库类上调用属性集访问器。现在在运行时我force应用程序针对另一个版本的库运行,其中类仅实现基类的底层接口(interface),但不是从它派生的。有趣的是,.NET将运行代码,但设置该属性没有任何效果。幕后发生了什么?违规代码:MyDbParameterparam=newMyDbParameter();param.ParameterName="p";Console.Out.WriteLine("ParameterName:"+param.ParameterName);库2.0(已编译)publicsealedclassMyDbParameter:System.

c# - IEnumerable Group 按用户指定的动态键列表

我有一个类publicclassEmpolyee{publicstringDesignation{get;set;}publicstringDiscipline{get;set;}publicintScale{get;set;}publicDateTimeDOB{get;set;}publicintSales{get;set;}}并以可枚举的方式记录所有员工ListEmployees;和一个字符串键列表,例如varKeys=newList(){"Designation","Scale","DOB"};假设列表“键”的元素是用户指定的,用户可以不指定或指定多个键元素。现在我想使用列表“K

c# - 如何在 Linq to SQL 中使用 distinct 和 group by

我正在尝试将以下sql转换为Linq2SQL:selectgroupId,count(distinct(userId))fromprocessroundissueinstancegroupbygroupId这是我的代码:varq=fromiinProcessRoundIssueInstancegroupibyi.GroupIDintogselectnew{Key=g.Key,Count=g.Select(x=>x.UserID).Distinct().Count()};当我运行代码时,我不断收到无效的GroupID。有任何想法吗?似乎distinct把事情搞砸了..这里是生成的sql:

c# - 犀牛模拟 : How to stub a generic method to catch an anonymous type?

我们需要stub一个通用方法,该方法将使用匿名类型作为类型参数来调用。考虑:interfaceIProgressReporter{TReport(TprogressUpdater);}//Unittestarrange:FuncreturnArg=(x=>x);//wewishtoreturntheargument_reporter.Stub(x=>x.Report(null).IgnoreArguments().Do(returnArg);如果在被测方法中对.Report()的实际调用是使用对象作为类型参数完成的,那么这将起作用,但实际上,调用该方法时使用的T是匿名类型。此类型在被测

c# - Visual Studio 2015 扩展方法调用作为方法组

我有一个类似的扩展方法publicstaticvoidRemoveDetail(thisTMastermaster,TChildchild)whereTMaster:class,IMasterwhereTChild:class,IDetail;我有两个类(class)publicclassPrincipal:IMaster{publicvirtualIEnumerablePermissions{get;}}和publicclassPermission:IDetail我从方法publicstaticvoidForeach(thisIEnumerablesource,Actionactio