公共静态字符串myString不返回字符串 [英] public static string myString is not returning a string

查看:178
本文介绍了公共静态字符串myString不返回字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了字符串行为.我在我的课程中有一个公共的静态字符串属性,如下所示.我将此作为参数传递给另一个接受字符串的方法,当代码运行时,它从该方法内引发异常,因为它 似乎甚至传递给该方法的东西也不是字符串,但是如果我在属性之后或属性内部添加.toString()可以解决问题.有人可以向我解释引擎盖下发生了什么吗?

im encountering a string behavior.  i have a public static string property in my class like below. i pass this in as a parameter into another method that accept a string, when the code runs, it throw a exception from within the method because it seems what even got passed into the method was not a string, but if i add .toString() after the property or inside my property solve the problem.  can any one explain to me what is going on under the hood?


      公共静态字符串MyFilePath
       {
          获取{return _appPath + _appSettings [_myfile]; }//在_appSettings [_myfile]之后添加.toString()还可防止异常
       }

        public static string MyFilePath
        {
            get { return _appPath + _appSettings[_myfile]; } //add .toString() after _appSettings[_myfile] also prevents exception
        }

someMethod(myClass.MyFilePath)//引发异常

someMethod(myClass.MyFilePath) //throw exception

someMethod(myClass.MyFilePath.toString())//没有异常

someMethod(myClass.MyFilePath.toString()) //no exception

someMethod(string aString)///不是我的方法,它来自另一个dll.

someMethod(string aString)///not my method, its from another dll.

{

做某事......

}

推荐答案

从您的描述中,我对_appSettings的类型有些怀疑.您能否确认它是否为字典类型,在这种情况下,它可能不会将字符串类型作为值给出.
From your description I am a little sceptic about the type of _appSettings. Can you confirm if its a dictionary type, in that case it may not be giving out string type as values.


这篇关于公共静态字符串myString不返回字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆