Possible Duplicate: What is a NullReferenceException in .NET? For example, " System.NullReferenceException was unhandled", with Message "Object reference not set to an instance of an object." What is the meaning of this exception, and how can it be solved? It means you've tried to access a member of something that isn't there: string s = null; int i = s.Length
可能重复: 什么是.NET中的NullReferenceException? 例如,“ System.NullReferenceException未处理”,消息“对象引用未设置为对象的实例”。 这个例外的意义是什么?如何解决? 这意味着你试图访问不存在的东西的成员: string s = null; int i = s.Length; // boom 只需修复空白的东西。 要么使它非空,要么先执行空测试。 这里还有一个关于Nullable<T> ,泛型和new通用约束的角落案例 - 虽然有点不太可能(
This question already has an answer here: What is a NullReferenceException, and how do I fix it? 33 answers 您需要首先初始化列表: protected List<string> list = new List<string>(); I think you just need; List<string> list = new List<string>(); list.Add("hai"); There is a difference between List<string> list; and List<string> list = new List<string
这个问题在这里已经有了答案: 什么是NullReferenceException,以及如何解决它? 33个答案 您需要首先初始化列表: protected List<string> list = new List<string>(); 我想你只是需要; List<string> list = new List<string>(); list.Add("hai"); 之间有区别 List<string> list; 和 List<string> list = new List<string>(); 当你在这种情况下没有使用new关键字时,你
This question already has an answer here: What is a NullReferenceException, and how do I fix it? 33 answers What does “Object reference not set to an instance of an object” mean? [duplicate] 8 answers The correct way in .NET 4.0 is: if (String.IsNullOrWhiteSpace(strSearch)) The String.IsNullOrWhiteSpace method used above is equivalent to: if (strSearch == null || strSearch == String.Em
这个问题在这里已经有了答案: 什么是NullReferenceException,以及如何解决它? 33个答案 “对象引用未设置为对象实例”是什么意思? [复制] 8个答案 .NET 4.0中的正确方法是: if (String.IsNullOrWhiteSpace(strSearch)) 上面使用的String.IsNullOrWhiteSpace方法等价于: if (strSearch == null || strSearch == String.Empty || strSearch.Trim().Length == 0) // String.Empty is the same as "" IsNullOrWhite
我如何使用Assert(或其他测试类?)来验证是否引发了异常? For "Visual Studio Team Test" it appears you apply the ExpectedException attribute to the test's method. Sample from the documentation here: A Unit Testing Walkthrough with Visual Studio Team Test [TestMethod] [ExpectedException(typeof(ArgumentException), "A userId of null was inappropriately allowed.")] public void Nul
我如何使用Assert(或其他测试类?)来验证是否引发了异常? 对于“Visual Studio团队测试”,看起来您将ExpectedException属性应用于测试的方法。 来自此处文档的示例:使用Visual Studio团队测试进行单元测试演练 [TestMethod] [ExpectedException(typeof(ArgumentException), "A userId of null was inappropriately allowed.")] public void NullUserIdInConstructor() { LogonInfo logonInfo = new LogonInfo(null,
I am going to be starting up a new project at work and want to get into unit testing. We will be using VS 2008, C#, and the ASP.NET MVC stuff. I am looking at using either NUnit or the built in test projects that VS2008 has, but I am open to researching other suggestions. Is one system better than the other or perhaps easier to use/understand than the other? I am looking to get this project s
我将在工作中启动一个新项目,并希望进入单元测试。 我们将使用VS 2008,C#和ASP.NET MVC的东西。 我正在考虑使用NUnit或VS2008内置的测试项目,但我愿意研究其他建议。 一个系统比另一个系统更好,或者比另一个更容易使用/理解? 我期待这个项目能够成为我们未来发展努力的“最佳实践”。 感谢您的任何帮助和建议! 道命名所有的VS2008测试项目的亲,这里是NUnit的亲。 NUnit有一个模拟框架。 NUnit可以在IDE之外运
I have a couple of ActionMethods that queries the Controller.User for its role like this bool isAdmin = User.IsInRole("admin"); acting conveniently on that condition. I'm starting to make tests for these methods with code like this [TestMethod] public void HomeController_Index_Should_Return_Non_Null_ViewPage() { HomeController controller = new HomePostController(); ActionResult
我有几个ActionMethods查询Controller.User的角色是这样的 bool isAdmin = User.IsInRole("admin"); 在这种情况下方便地行事。 我开始用这样的代码对这些方法进行测试 [TestMethod] public void HomeController_Index_Should_Return_Non_Null_ViewPage() { HomeController controller = new HomePostController(); ActionResult index = controller.Index(); Assert.IsNotNull(index); } 并且该测试失败,因
I am very, very new to unit testing and am trying to write a test for a pretty simple method: public class myClass : RequireHttpsAttribute { public override void OnAuthorization(AuthoizationContext filterContext) { var request = filterContext.HttpContext.Request; var header = Convert.ToBoolean(request.Headers["Special-Header-Name"]); if (!(header || request.IsSec
我对单元测试非常非常新,我正在尝试编写一个非常简单的测试方法: public class myClass : RequireHttpsAttribute { public override void OnAuthorization(AuthoizationContext filterContext) { var request = filterContext.HttpContext.Request; var header = Convert.ToBoolean(request.Headers["Special-Header-Name"]); if (!(header || request.IsSecureConnection)) {
const double pi = 3.1415926535897; static double mysin(double x) { return ((((((-0.000140298 * x - 0.00021075890) * x + 0.008703147) * x - 0.0003853080) * x - 0.16641544) * x - 0.00010117316) * x + 1.000023121) * x; } static void Main(string[] args) { Stopwatch sw = new Stopwatch(); double a = 0; double[] arg = new double[1000000]; for (int i = 0; i < 1000
const double pi = 3.1415926535897; static double mysin(double x) { return ((((((-0.000140298 * x - 0.00021075890) * x + 0.008703147) * x - 0.0003853080) * x - 0.16641544) * x - 0.00010117316) * x + 1.000023121) * x; } static void Main(string[] args) { Stopwatch sw = new Stopwatch(); double a = 0; double[] arg = new double[1000000]; for (int i = 0; i < 1000
I am trying to determine if a user downloaded a file from FTP using MS Log Parser 2.2 I have not been able to get parser SQL query going, although I have used several samples queries. Water Down Parser Query does not work: strSQL = "SELECT date,COUNT(*) AS downloads,c-ip " strSQL = strSQL & "FROM C:tempLog*.log " strSQL = strSQL & "WHERE cs-method='RETR' " strSQL = strSQL & "GROU
我试图确定用户是否使用MS Log Parser 2.2从FTP下载文件 尽管我已经使用了多个示例查询,但我仍然无法获取解析器SQL查询。 水下分析器查询不起作用: strSQL = "SELECT date,COUNT(*) AS downloads,c-ip " strSQL = strSQL & "FROM C:tempLog*.log " strSQL = strSQL & "WHERE cs-method='RETR' " strSQL = strSQL & "GROUP BY date,c-ip " 错误: RecordSet cannot be used at this time [Unknown Error]
It seems that versioning works differently than in previous versions of .Net. The project.json seems to use semantic versioning (from what I have seen online) with the format Major.Minor.Patch-Special. Does this replace the Assembly version idea or add to it? Or does it just get used with Nuget. How does one access the version during runtime. I came across Nuget.SemanticVersion object onli
看起来,版本控制的工作方式与之前版本的.Net不同。 project.json似乎使用Major.Minor.Patch-Special格式的语义版本(从我在线看到的)。 这是否取代汇编版本的想法或添加到它? 或者它只是用于Nuget。 在运行时如何访问版本。 我在Microsoft.Framework.Runtime包中在线遇到了Nuget.SemanticVersion对象,但我无法找到如何在代码中检索它。 是否有编程方式更新构建上的这个值或者只是自定义脚本? 我不会说版本控制的