在类库中传递字符串 [英] passing string in classlibrary class

查看:52
本文介绍了在类库中传递字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在传递类库类中的字符串时遇到一些困难,以至于我必须传递参数,并且如果false为1和0,则返回false

i am facing some difficulties in passing a string in classlibrary class,such that i have to pass the parameters and return true if 1 and 0 for false

推荐答案

根据问题,如果输入为1,则输出为true ,否则为false.

Based on the question, if input is 1 then output will be true otherwise false.

static bool ConvertToBoolean(string dataToParse)
{
    List<string> booleanList = new List<string> { "1", "0" };
    return string.IsNullOrEmpty(dataToParse) ? false : booleanList.Contains(dataToParse);
}



已更新:



Updated:

static bool ConvertToBoolean(string dataToParse)
{
    string trueString = "1";
    return string.IsNullOrEmpty(dataToParse) ? false : dataToParse == trueString;
}




希望对您有所帮助.
:)




Hope it helps.
:)


int x = Convert.ToInt32(Convert.ToBoolean("true"));
int y = Convert.ToInt32(Convert.ToBoolean("false"));



运行上面的代码后,x将为1,y将为0.



After running the code above, x will be 1, and y will be 0.


这篇关于在类库中传递字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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