草庐IT

c# - 错误 : A project with an out put type of class library

我试图找出.net并得到这段代码,当我尝试从VS2008运行时它给我这个错误AprojectwithanOutputTypeofClassLibrarycannotbestarteddirectly.Inordertodebugthisproject,addanexecutableprojecttothissolutionwhichreferencestothelibraryproject.Settheexecutableprojectasthestartupproject我正在学习C#,所以不知道该做什么 最佳答案 您不能运行库。

c# - 什么是 Type.GUID,它与 Type.Equals() 有什么关系?

我在尝试将System.RuntimeType的实例与泛型类型TOut进行比较时遇到了一些有趣的行为:TyperuntimeT=methodInfo.ReturnType;//getRuntimeTypeusingreflectionTypegenericT=typeof(TOut);//ThisconditionfailsbecauseruntimeTdoesn't//seemtoincludeanassemblyqualifiednameif(runtimeT.Equals(genericT)){...}这是我的证据:免责声明:我不知道GUID在CLR/类型系统的上下文中到底是什么

c# - 如何从 C# 中的异步任务 <bool> 函数获取 bool 结果 - 错误 : Cannot implicitly convert type `void' to `bool'

我已经创建了任务函数来验证我的json文件。一切正常,直到我没有使用结果。当我试图从asynctaskfunction获得结果时它显示错误为Cannotimplicitlyconvert'void'tobool.我的异步函数如下:privateasyncTaskMyValidationFunction(stringjson){boolisValid=true;.......DOINGMYVALIDATIONSTUFF.....returnisValid;}从另一个函数调用这个函数如下:publicboolGetJsonAndValidate(){boolisValid=true;str

c# - 错误 CS0051(不一致的可访问性 : parameter type 'Job' is less accessible than method 'AddJobs.TotalPay(Job)' )

我通过省略totalFee字段成功编译并运行了下面的源代码。如何将totalFee写入此程序,以便它准确计算每项工作的总费用(费率*时间)?下面,您会看到我尝试使用一种方法;这产生了错误CS0051(可访问性不一致:参数类型“Job”的可访问性低于方法“AddJobs.TotalPay(Job)”)。此源代码是对以下作业的响应:"DesignaJobclassforHarold’sHomeServices.Theclasscontainsfourdatafields—Jobdescription(forexample,“washwindows”),timeinhourstocomple

c# - 如何为 "T must be a reference type"编写单元测试?

考虑:classMyClasswhereT:class{}在这种情况下,where子句强制执行MyClass只是引用类型的泛型的规范。理想情况下,我应该有一个测试此规范的单元测试。然而,这个单元测试显然行不通,但它解释了我想要完成的事情:[Test][DoesNotCompile()]publicvoidT_must_be_a_reference_type(){vartest=newMyClass();}如何测试通过不允许代码编译实现的规范?编辑:更多信息:好的,所以我这样做的理由(哈哈)是我一直在遵循TDD方法,在这种方法中,除非单元测试失败,否则您不能编写任何代码。假设您有这个:c

c# - 可访问性不一致 : return type is less accessible than method C#

好吧,这真的很奇怪。我有一个私有(private)成员,我想将它用于Form2。我创建了一个公共(public)静态方法,以便我可以将该成员放入Form2。这是我的代码:privatestaticAppControllerappController;privateBreadRepositorybreadRep;privateCakeRepositorycakeRep;privateSandwichRepositorysandwichRep;publicForm1(){InitializeComponent();breadRep=newBreadRepository();cakeRep=

c# - 在 C# 中,Type.FullName 何时返回 null?

MSDNforType.FullName说这个属性返回nullifthecurrentinstancerepresentsagenerictypeparameter,anarraytype,pointertype,orbyreftypebasedonatypeparameter,oragenerictypethatisnotagenerictypedefinitionbutcontainsunresolvedtypeparameters.我数了五种情况,发现一个比一个更不清楚。这是我尝试构建每个案例的示例。usingSystem;usingSystem.Collections.Gene

c# - "new"inside concrete type projection 只被调用一次

我有简单的Linq2Sql查询:varresult=fromtinMyContext.MyItemsselectnewMyViewModelClass(){FirstProperty=t,SecondProperty=newSomeLinq2SqlEntity()}问题是newSomeLinq2SqlEntity()似乎只对该序列执行一次,因此查询结果中MyViewModelClass的所有实例共享链接到一个对象。更新:这是我快速检查它的方法:result[0].SecondProperty.MyField=10;使用调试器,我可以检查MyField在所有情况下都设置为10。当我用fo

c# - Content-Type 字符集是否未从 HttpResponseMessage 公开?

我正在将一些代码从使用HttpWebRequest转换为HttpClient。我遇到的一个问题是从内容类型响应header获取字符集。使用HttpWebRequest时,字符集在HttpWebResponse.CharacterSet属性中公开,如下所示using(WebResponseresponse=awaitthis.webRequest.GetResponseAsync()){stringcharacterSet=((HttpWebResponse)response).CharacterSet;您还可以从WebResponse.ContentType属性或从HttpWebRes

c# - "Unable to cast object of type ' System.Net.Http.Formatting.JsonContractResolver ' to type ' Newtonsoft.Json.Serialization.DefaultContractResolver '."

我们有一个最近被转移到新服务器的WEBAPI项目。在对项目的有效负载进行一些添加后,我正在运行我的项目,但它突然抛出以下错误:Unabletocastobjectoftype'System.Net.Http.Formatting.JsonContractResolver'totype'Newtonsoft.Json.Serialization.DefaultContractResolver'.有问题的代码行在global.asax中:protectedvoidApplication_Start(){GlobalConfiguration.Configure(WebApiConfig.R