将字符串转换为bool [英] Convert a string to bool

查看:597
本文介绍了将字符串转换为bool的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个来自字段(int)的值,如

字符串strPlayerLoginStatus = dsPlayer2.Tables [0] .Rows [0] [1] .ToString();


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

中使用它如果声明


如何转换变量?


问候


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

推荐答案

" 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" <再**** @ eivon.no>在消息中写道

新闻: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



这篇关于将字符串转换为bool的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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