简体   繁体   English

如何修复int不包含int.TryParse()的定义?

[英]How to fix int does not contain a definition for int.TryParse()?

In my new CF winform I suddenly cannot code int.TryParse() , with VS showing the message 'int' does not contain a definition for 'TryParse' , but in another form this is no problem. 在我的新CF winform中,我突然无法编码int.TryParse() ,而VS显示消息'int' does not contain a definition for 'TryParse' ,但是以另一种形式,这没问题。 So strange! 这么奇怪!

I tracked this down, with Go To Definition, that the old form uses int from C:\\DOCUME~1\\XPMUser\\LOCALS~1\\Temp\\3464$CommonLanguageRuntimeLibrary$v2.0.50727\\System.Int32.cs which of course has TryParse() , while my new code uses int from C:\\DOCUME~1\\XPMUser\\LOCALS~1\\Temp\\3464$mscorlib.dll$v2.0.50727\\System.Int32.cs , which has no TryParse() . 我跟踪下来,用转到定义,旧形式的采用intC:\\DOCUME~1\\XPMUser\\LOCALS~1\\Temp\\3464$CommonLanguageRuntimeLibrary$v2.0.50727\\System.Int32.cs这当然具有TryParse() ,而我的新代码使用了C:\\DOCUME~1\\XPMUser\\LOCALS~1\\Temp\\3464$mscorlib.dll$v2.0.50727\\System.Int32.cs int ,后者没有TryParse()

In the list of references of the project, there is a mscorlib , and by double-clicking I arrive in the Object Browser at mscorlib [Compact Framework] , while the object browser also shows an entry mscorlib , ie without the CF remark. 在项目的引用列表中,有一个mscorlib ,通过双击我进入对象浏览器中的mscorlib [Compact Framework] ,而对象浏览器还显示了一个条目mscorlib ,即没有CF标记。

This did not help me much, hopefully someone can help me get TryParse() back. 这对我没有太大帮助,希望有人可以帮助我找回TryParse()。

Here is sample code with the error: 这是带有错误的示例代码:

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace SIClient2.WebServices
{
    class Test
    {
        public Test()
        {
            int i;
            int.TryParse("123", out i); // <== 'int' does not contain a definition for 'TryParse'
        }
    }
}

The code without the error is part of a winform. 没有错误的代码是winform的一部分。 Does that make a diff? 这有什么区别吗?

This turned out to be one of the things you should not do on a Friday afternoon. 原来这是星期五下午您不应该做的事情之一。 The solution has several projects: a client on a mobile device, hence CF. 该解决方案有几个项目:移动设备上的客户端,因此是CF。 A server for web services. Web服务服务器。 And a test project that calls the web services directly for easier debugging, with desktop winforms, ie, without CF, and with int.TryParse() ... :-) We are also working on upgrading to more modern mobile devices which will hopefully avoid CF. 还有一个测试项目,该项目直接调用Web服务以使用台式机Winforms(即不使用CF并使用int.TryParse()... :-)来更容易地调试,我们也在努力升级到更现代的移动设备,希望该设备可以避免CF。

The bottom line is that VS is not that bad, but not very easy either. 最重要的是,VS并不是那么糟糕,但是也不是很容易。 Most errors are valid pointers to real problems. 大多数错误是指向实际问题的有效指针。 On the other hand regrettable that CF is so limited, while today's mobile devices are not that petite anymore. 另一方面,令人遗憾的是CF如此有限,而如今的移动设备不再那么小巧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM