草庐IT

class_methods

全部标签

c# - 部分类(class)的目的是什么?

我读了aboutpartialclasses并且,例如,我理解在VisualStudio创建Windows窗体时使用它们的原因,但不排除whenworkingonlargeprojects,spreadingaclassoverseparatefilesenablesmultipleprogrammerstoworkonitatthesametime.后来我看了thisexample我注意到大多数类都被声明为部分类。为什么? 最佳答案 部分类很有用的一个很好的例子是当类由工具(如VS)自动生成并且您希望能够扩展该类的功能并且在工具需

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# - 犀牛模拟 : 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# - 哪个是 delphi "class of "(类的类型)的 C# 声明?

在delphi中,我可以像这样声明一个类型的类typeTFooClass=classofTFoo;TFoo=classend;此声明的C#等效项是什么? 最佳答案 您在C#中可以获得的最接近的是Type类型,它包含有关类型的元数据。publicclassA{}publicstaticintMain(string[]args){Typeb=typeof(A);}这不是完全相同的。在Delphi中,“其他类型的类型”本身就是可以分配给变量的类型。在C#中,“其他类型的类型”是一个System.Type实例,可以分配给System.Typ

c# - 在抽象父类(super class)的子类中强制使用属性

如何强制子类实现其父类(superclass)的某些属性?原因是我想使用属性来获取有关该类的一般信息,例如“显示名称”、“说明”或“功能”。所以我想我可以在父类(superclass)中实现它们并强制子类实现这些属性。是否有类似于方法的抽象属性?[abstractDeclareMe]publicabstractclassInheritMe{publicabstractvoidDeclareMe();} 最佳答案 由于你的类迟早要运行,你可以在你的基类中添加检查机制来验证你的子类中某些属性的存在。这里有一些示例代码。classProg

c# - 通过安装程序设置模拟属性会导致 'Expression is not a method invocation'

我有下面的代码,其中我的Mock接口(interface)有一个Recorder属性,它是一个类。然后我尝试在该类上设置一个属性,但我得到了一个Expressionisnotamethodinvocation错误。你能帮忙吗?错误是在运行时尝试设置枚举属性时出现的。它会抛出一个带有以下堆栈跟踪的ArgumentException:atMoq.ExpressionExtensions.ToMethodCall(LambdaExpressionexpression)atMoq.Mock.c__DisplayClass1c`2.b__1b()atMoq.PexProtector.Invoke

C# 错误 : The call is ambiguous between the following methods or properties. 运算符重载

我在名为Dinero的命名空间中有2个带有重载运算符的类,这些是2个类:第一个:namespaceDinero{classDollar{#regionAtributospublicDoublecant;#endregion#regionConstructorespublicDollar(){this.cant=0;}publicDollar(Doubleamount){this.cant=amount;}#endregion#regionSobrecargadeOperadorespublicstaticDollaroperator+(Euroeu,Dollardol){Dollard

c# - 如何: Use async methods with LINQ custom extension method

我有一个LINQ自定义扩展方法:publicstaticIEnumerableDistinctBy(thisIEnumerableitems,Funcproperty){returnitems.GroupBy(property).Select(x=>x.First());}我是这样使用它的:varspc=context.pcs.DistinctBy(w=>w.province).Select(w=>new{abc=w}).ToList();但问题是我不想要ToList()我想要这样的东西varspc=awaitcontext.pcs.DistinctBy(w=>w.province).

c# - 是什么导致 Xamarin Forms 构建出现 "unrecognized selector sent to class"错误?

首先介绍一下我的系统:Mac操作系统版本10.13.6Xcode版本10VisualStudioformac7.6.6我对Xamarin表单完全陌生,想尝试和学习。我想要做的只是创建一个新的xamarin表单解决方案并开始构建。以下是我经历的步骤:创建新项目从多平台的应用程序子菜单中选择C#中的“空白表单应用程序”目标平台包括Andriod和iOs;共享代码.NETStandard不要为版本控制或应用中心测试而烦恼(未勾选)这里是错误:https://github.com/benfranklin79/shared/blob/master/20180919/error.txt这是解决方案