草庐IT

help-system

全部标签

c# - 从类型的部分名称获取 System.Type

我想得到一个System.Type,只给string中的类型名称。例如,如果我有一个对象:MyClassabc=newMyClass();然后我可以说:System.Typetype=abc.GetType();但是如果我只有:stringclassName="MyClass"; 最佳答案 这取决于该类是哪个程序集。如果它在mscorlib中或调用程序集,您只需要Typetype=Type.GetType("namespace.class");但如果它是从其他程序集引用的,则需要执行以下操作:Assemblyassembly=typ

C# 下列方法或属性之间的调用不明确 : 'System.Math.Round(double, int)' and 'System. Math.Round(decimal, int)

由于以下错误,我的代码无法编译:以下方法或属性之间的调用不明确:“System.Math.Round(double,int)”和“System.Math.Round(decimal,int)”我的代码是Math.Round(newFileInfo(strFilePath).Length/1024,1)我该如何解决这个问题?谢谢 最佳答案 Math.Round(newFileInfo(strFilePath).Length/1024d,1) 关于C#下列方法或属性之间的调用不明确:'Sys

C# 下列方法或属性之间的调用不明确 : 'System.Math.Round(double, int)' and 'System. Math.Round(decimal, int)

由于以下错误,我的代码无法编译:以下方法或属性之间的调用不明确:“System.Math.Round(double,int)”和“System.Math.Round(decimal,int)”我的代码是Math.Round(newFileInfo(strFilePath).Length/1024,1)我该如何解决这个问题?谢谢 最佳答案 Math.Round(newFileInfo(strFilePath).Length/1024d,1) 关于C#下列方法或属性之间的调用不明确:'Sys

c# - 未找到具有不变名称 'System.Data.SqlClient' 的 ADO.NET 提供程序的 Entity Framework 提供程序。

我们使用EntityFramework6和CodeFirst。我们有一个控制台应用程序,它没有引用EntityFramework,而是从其App.config中读取连接字符串。它调用DatabaseInitializationUtilities程序集,将连接字符串作为参数传递。DatabaseInitializationUtilities引用了EF6(EntityFramework和EntityFramework.SqlServer)。它的App.config是这样的:当执行到DatabaseInitializationUtilities尝试运行脚本的行时context.Databas

c# - 未找到具有不变名称 'System.Data.SqlClient' 的 ADO.NET 提供程序的 Entity Framework 提供程序。

我们使用EntityFramework6和CodeFirst。我们有一个控制台应用程序,它没有引用EntityFramework,而是从其App.config中读取连接字符串。它调用DatabaseInitializationUtilities程序集,将连接字符串作为参数传递。DatabaseInitializationUtilities引用了EF6(EntityFramework和EntityFramework.SqlServer)。它的App.config是这样的:当执行到DatabaseInitializationUtilities尝试运行脚本的行时context.Databas

c# - 更改了 .NET 4.5 中 string.Empty(或 System.String::Empty)的行为

短版:C#代码typeof(string).GetField("Empty").SetValue(null,"Helloworld!");Console.WriteLine(string.Empty);编译并运行时,给出输出"Helloworld!"在.NET4.0及更早版本下,但提供""在.NET4.5和.NET4.5.1下。如何像这样忽略对字段的写入,或者谁重置该字段?加长版:我从来没有真正理解为什么string.Empty字段(也称为[mscorlib]System.String::Empty)不是const(又名literal),参见“Whyisn'tString.Emptya

c# - 更改了 .NET 4.5 中 string.Empty(或 System.String::Empty)的行为

短版:C#代码typeof(string).GetField("Empty").SetValue(null,"Helloworld!");Console.WriteLine(string.Empty);编译并运行时,给出输出"Helloworld!"在.NET4.0及更早版本下,但提供""在.NET4.5和.NET4.5.1下。如何像这样忽略对字段的写入,或者谁重置该字段?加长版:我从来没有真正理解为什么string.Empty字段(也称为[mscorlib]System.String::Empty)不是const(又名literal),参见“Whyisn'tString.Emptya

c# - 为什么 Entity Framework 6.1.3 会抛出 "Could not load type ' System.Data.Entity.Infrastructure.TableExistenceChecker'”

由于上下文实例一创建就抛出异常,全新的项目和EntityFramework将无法启动。EntityFramework抛出以下异常:Couldnotloadtype'System.Data.Entity.Infrastructure.TableExistenceChecker'fromassembly'EntityFramework,Version=6.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089'.引用资料:EntityFrameworkEntityFramework.SqLServer通过nuget包管理器:Install

c# - 为什么 Entity Framework 6.1.3 会抛出 "Could not load type ' System.Data.Entity.Infrastructure.TableExistenceChecker'”

由于上下文实例一创建就抛出异常,全新的项目和EntityFramework将无法启动。EntityFramework抛出以下异常:Couldnotloadtype'System.Data.Entity.Infrastructure.TableExistenceChecker'fromassembly'EntityFramework,Version=6.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089'.引用资料:EntityFrameworkEntityFramework.SqLServer通过nuget包管理器:Install

c# - 可以从 System.ArgumentException 派生吗?

如果我有一个检查其参数有效性的方法,是否可以抛出派生自System.ArgumentException的自定义异常?我问是因为ArgumentException本身是从System.SystemException派生的,而且我看到关于应用程序是否应该从SystemException派生的指南存在冲突。(尽管是间接的,从ArgumentException派生仍然等同于从SystemException派生。)我看到很多指南说不要派生自ApplicationException,而是派生自Exception。我对此很满意。我不确定是否也可以从SystemException派生。如果我不应该从S