all groups > c# > february 2005 >
You're in the

c#

group:

Convert a string to bool


Re: Convert a string to bool Bob Calvanese
2/19/2005 12:33:42 PM
c#:
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
[quoted text, click to view]

Re: Convert a string to bool Nick Malik [Microsoft]
2/19/2005 3:49:35 PM
[quoted text, click to view]

I disagree with you, Zach. The ng is open to all, regardless of experience.
If a question is too trivial for you, don't answer it.

To ReidarT
You are welcome here.

[quoted text, click to view]

I've heard a lot of weird things before, but this is pretty weird. The book
has a few minor errors in the use of C#, specifically in the demonstration
of a single pattern. The rest of the book is above average, and the first
chapters are excellent (as you noted). If he or she doesn't know design
patterns, the OP may benefit from reading this book in its entirety
(although I usually recommend Shalloway's book for folks just learning DP).


--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--

Re: Convert a string to bool NeoNet
2/19/2005 5:26:11 PM
"ReidarT" <reidar@eivon.no> ha scritto nel messaggio
news:O4u$TaqFFHA.3648@TK2MSFTNGP10.phx.gbl...

[quoted text, click to view]

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]);

[quoted text, click to view]

Another way?

// if Rows contains a int as string
int intPlayerLoginStatus =
int.Parse(dsPlayer2.Tables[0].Rows[0][1].ToString());

--
Reporting tool: http://www.neodatatype.net

Convert a string to bool ReidarT
2/19/2005 6:15:07 PM
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

Re: Convert a string to bool Tyron Madlener
2/19/2005 6:24:39 PM
Re: Convert a string to bool Zach
2/19/2005 6:49:13 PM
[quoted text, click to view]

<snipped>

[quoted text, click to view]

You would need to know which int value is ok (say 1) and which is not ok.

if (some_value == 1)
{
// do something
}

Unless we are completely misunderstanding you,
you need to read a textbook on C#. You shouldn't
use this ng to learn the basics of C#, but to help
you solve problems after the learning stage.

If you have a good library in the neighbourhood
photocopy the first 100 pages of C# Design Patterns by James W. Cooper
ISBN 0-201-84453-2 Don't read the rest of the book. Don't buy the book.
It gives you a super brief and well written introduction into the basics of
C#.

Else buy / read
Learning C# O'Reilly ISBN 0-596-00376-5








Re: Convert a string to bool Meylum
2/19/2005 6:54:21 PM
try
{
int value = int.Parse( strPlayerLoginStatus );
}
catch (System.FormatException ex)
{
// handle exception
}


"ReidarT" <reidar@eivon.no> schreef in bericht
news:O4u$TaqFFHA.3648@TK2MSFTNGP10.phx.gbl...
[quoted text, click to view]

Re: Convert a string to bool Peter Rilling
2/19/2005 11:32:38 PM
Also, one person's trivial task is another person's challenge.

[quoted text, click to view]

Re: Convert a string to bool ReidarT
2/20/2005 10:38:38 AM
Thanks, thats good to hear
reidarT
"Nick Malik [Microsoft]" <nickmalik@hotmail.nospam.com> skrev i melding
news:i_mdndJDKP3iTYrfRVn-1g@comcast.com...
[quoted text, click to view]

Re: Convert a string to bool Zach
2/20/2005 11:10:28 AM

[quoted text, click to view]

Re Cooper:

[quoted text, click to view]

Yes, I get the impression that you have!

(1) There are better books around on the subject of design patterns
(2) The subject matter and the examples used are totally unsuited for
an *absolute* starter.

Re using the ng by an *absolute* starter:
First reading an introductory text will get the OP up to
speed faster. To that end I suggested two excellent texts,
one very concise but sufficient for starters, the other
more comprehensive.






AddThis Social Bookmark Button