- - PR -
Question about Boolean
1
投稿者 | 投稿内容 | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
投稿日時: 2006-03-04 02:52
I'm sorry. I cannot type in Japanese because now I'm in the U.S.
I have a problem writing boolean . Monster class **************************************** public boolean hasHealth(){ if(health>0){ return true; } else return false; } /************************************** When I call hasHealth() method to a main class. How can I call this function? I wanna use if statement. Monster mon = new Monster; If (mon.hasHealth()= true){ } I wrote as above, but I got an error. Could you tell me how to write If statement to use boolean. Thank you!! | ||||||||||||||||||||||||
|
投稿日時: 2006-03-04 03:30
if (mon.hasHealth() == true){ 記述言語が C# であるなら、「If ではなく if」「= ではなく ==」です。 ついでに言えば
のがいいかも。 _________________ // 渋木宏明 (Hiroaki SHIBUKI) // http://hidori.jp/ // Microsoft MVP for Visual C# // // @IT会議室 RSS 配信中: http://hidori.jp/rss/atmarkIT/ | ||||||||||||||||||||||||
|
投稿日時: 2006-03-04 04:25
Thank you for the reply.
My problem was resolved when i wrote as you said. I appreciate it | ||||||||||||||||||||||||
|
投稿日時: 2006-03-04 10:03
あ、日本の方でしたか...
boolean ですか... C# ではなく Java かな?
単純式ならそのまま比較結果を return してもいいけど、こっちの方が好きかな。
インスタンス化において括弧が必要なハズです。 また、「If」は「if」と書かなければなりません。 評価結果として true を書く必要はありません。
で false の場合は、こうします。
_________________ C# と VB.NET の入門サイト じゃんぬねっと日誌 |
1