且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将字符串转换为bool

更新时间:2023-02-03 08:33:06

" ReidarT" <再**** @ eivon.no> ha scritto nel messaggio

新闻:O4 ************** @ TK2MSFTNGP10.phx.gbl ...
"ReidarT" <re****@eivon.no> ha scritto nel messaggio
news:O4**************@TK2MSFTNGP10.phx.gbl...
我有一个表中字段(int)的值,如
字符串strPlayerLoginStatus = dsPlayer2.Tables [0] .Rows [0] [1] .ToString();


为什么你不能直接得到它?


//如果Rows包含一个int

int intPlayerLoginStatus =(int)dsPlayer2.Tables [0] .Rows [0] [1];


//如果Rows包含类似于int的内容

int intPlayerLoginStatus = Convert.ToInt32(dsPlayer2.Tables [0] .Rows [0] [1]);

我喜欢将strPlayerLoginStatus从string转换为int以在

如何转换变量?
I have a value from a field (int) in a table like
string strPlayerLoginStatus = dsPlayer2.Tables[0].Rows[0][1].ToString();
Why don''t you get it as you want directly?

// if Rows contains an int
int intPlayerLoginStatus = (int)dsPlayer2.Tables[0].Rows[0][1];

// if Rows contains something similar to an int
int intPlayerLoginStatus = Convert.ToInt32(dsPlayer2.Tables[0].Rows[0][1]);
I like to convert the strPlayerLoginStatus from string to int to use it in
an if statement

How do I convert the variable?




另一种方式?


//如果Rows包含int作为字符串

int intPlayerLoginStatus =

int.Parse(dsPlayer2.Tables [0] .Rows [0] [1] .ToString( ));


-

报告工具: http://www.neodatatype.net


Convert.ToInt32(strPlayerLoginStatus);
Convert.ToInt32(strPlayerLoginStatus);


如果你有记录,你想要bool是真的吗?如果你这样做是假的?
不是吗?


如果是这样的话......给方法一个返回类型的bool并根据
返回它
结果。


公共布尔GetTheData()

{

if(表有记录......)

{

返回true;

}

其他

{

返回false;

}

}


public void CallingMethod()

{

if(GetTheData)

{

做点什么...

}

其他

{

做别的事......

}

}


希望这会有所帮助。

bobc

" ReidarT" &LT;再**** @ eivon.no&GT;在消息中写道

新闻:O4 ************** @ TK2MSFTNGP10.phx.gbl ...
Do you want the bool to be true if you have a record and false if you do
not?

If so... Give the method a return typ of bool and return it based on the
result.

public bool GetTheData()
{
if(the table has records...)
{
return true;
}
else
{
return false;
}
}

public void CallingMethod()
{
if(GetTheData)
{
do something...
}
else
{
do something else...
}
}

Hope this helps.
bobc
"ReidarT" <re****@eivon.no> wrote in message
news:O4**************@TK2MSFTNGP10.phx.gbl...
我的价值来自表格中的字段(int)如
字符串strPlayerLoginStatus = dsPlayer2.Tables [0] .Rows [0] [1] .ToString();

我想转换strPlayerLoginStatus来自字符串到int以在if语句中使用它

如何转换变量?

问候语

reidarT >
I have a value from a field (int) in a table like
string strPlayerLoginStatus = dsPlayer2.Tables[0].Rows[0][1].ToString();

I like to convert the strPlayerLoginStatus from string to int to use it in
an if statement

How do I convert the variable?

regards

reidarT