草庐IT

System虚拟化

全部标签

c# - 为什么我们使用虚拟和覆盖?

如果不使用override和virtual效果一样,为什么还要使用override和virtual?示例1:classBaseClass{publicvirtualstringcall(){return"A";}}classDerivedClass:BaseClass{publicoverridestringcall(){return"B";}}输出:B示例2:classBaseClass{publicstringcall(){return"A";}}classDerivedClass:BaseClass{publicstringcall(){return"B";}}输出还是一样:输出

c# - 从物理路径转换为虚拟路径

我有这个函数可以将文件数据作为字节数组和文件路径获取。我得到的错误是当它试图在代码bewlo中设置fileInfo时。它说“给定物理路径,期望虚拟路径”publicoverridevoidWriteBinaryStorage(byte[]fileData,stringfilePath){try{//Createdirectoryifnotexists.System.IO.FileInfofileInfo=newSystem.IO.FileInfo(System.Web.HttpContext.Current.Server.MapPath(filePath));//whenitgetst

c# - 如何在 C# 中从 System.Array 转换为 object[]

我有一个COM函数需要object[]作为参数:foo(object[]values)我想将一些enum字段传递给它,所以我使用以下内容:object[]fields=(object[])Enum.GetValues(typeof(SomeEnumType));但是,当我尝试将fields传递给foo(...)时,即[foo(fields)]我得到一个错误:"Unabletocastobjectoftype`SomeEnumType[]'totype'system.Object[]'.谁能告诉我我做错了什么? 最佳答案 如异常所述,

c# - 将 xml 反序列化为对象时出错 : System. FormatException 输入字符串格式不正确

您好,在此先感谢您的帮助。我在尝试使用XmlSerializer和StringReader将XElement反序列化为对象时遇到问题。我的反序列化代码是这样的:/*deseierializeasingleRegisterServerObjectinstancefromxml*/staticRegisterServerObjectDeserializeSingleServerFromXml(XElementserverElement){XmlSerializerdeserializer=newXmlSerializer(typeof(RegisterServerObject));Regi

c# - “System.DateTime”不是有效的 Windows 运行时参数类型

我使用的是C#类,它在我的Windows应用商店应用程序(C#)中运行良好。但是当我尝试在Windows运行时组件中使用它时,出现以下错误:Calculator.Calculate(System.DateTime)'hasparameter'dateTime'oftype'System.DateTime'.'System.DateTime'isnotavalidWindowsRuntimeparametertype.类中的示例对象:publicDateTimeCalculate(DateTimedateTime){intdayNumberOfDateTime=ExtractDayNum

c# - DropCreateDatabaseIfModelChanges EF6 导致 System.InvalidOperationException : The model backing the context has changed

迁移到EntityFramework6后,我在构建服务器上执行单元测试时遇到错误。我正在使用DropCreateDatabaseIfModelChanges初始化程序。当我将其更改为MigrateDatabaseToLatestVersion时一切正常,但我想坚持使用之前的初始化程序。我得到的错误是:System.InvalidOperationException:System.InvalidOperationException:Themodelbackingthe'AppContext'contexthaschangedsincethedatabasewascreated.Consi

c# - 为什么这会呈现为 "System.Web.Mvc.SelectListItem"的列表?

我正在尝试使用从属性中提取的值来填充DropDownList,而我现在的最终结果是一个只有“System.Web.Mvc.SelectListItem”的列表。我确定我在这里省略了一些小步骤,但我终究无法弄清楚它是什么。生成列表的属性GET:publicIEnumerableAllFoo{get{varfoo=fromginBarorderbyg.nameselectnewSelectListItem{Value=g.fooid.ToString(),Text=g.name};returnfoo.AsEnumerable();}}Controller代码:publicActionRes

c# - 获取 url 的主要部分,包括虚拟目录

我正在使用.net4.0c#。我希望能够从当前的http请求中获取url,包括任何虚拟目录。因此,例如(请求和寻求值(value)):http://www.website.com/shop/test.aspx->http://www.website.com/shop/http://www.website.com/test.aspx->http://www.website.com/http://website.com/test.aspx->http://website.com/如何实现这一目标? 最佳答案 这是我用的HttpConte

c# - 错误 : Cannot implicitly convert type 'void' to 'System.Collections.Generic.List'

我正在尝试使用该控件从.ascx设置我的.ascx控件的属性。所以在我的一个包含此控件的.aspx中,我有以下代码试图设置我的嵌入式.ascx的ItemsList属性:Itemitem=GetItem(itemID);myUsercontrol.ItemList=newList().Add(item);我尝试设置的.ascx中的属性如下所示:publicListItemsList{get{returnthis.itemsList;}set{this.itemsList=value;}}错误:无法将类型“void”隐式转换为“System.Collections.Generic.List

c# - .Net 4.0 System.Web.Security.MembershipProvider 引用不明确?

我最近将我的BlogEngine.Net安装升级到1.6和.Net4.0,但是,我在执行升级时没有构建BlogEngine.Core。但是,当我现在尝试构建BlogEngine.Core项目时,编译失败,因为它无法加载(System.Web.Security.)MembershipProvider的符号。我认为这是一个.Net/C#/user问题,而不是BlogEngine问题。该项目引用了System.Web库,类文件(继承自MembershipProvider)包含一个用于System.Web.Security的Using。启用ReSharper后,IntelliSense会指示混