none
Is 'bool' incorrect data type in visual C#.NET? RRS feed

  • Question

  • I was composing a function invisual studio 2013 preview

    I wrote

    public bool CheckNumber(string strText)

    {

    ...............

    return true;

    }

    When I tried to build, I found CompileTime ErrorMessage, saying,"Expected Class,delegate,enum, or struct." with red line under the return type, bool. From the time Iwas faced to C#.NET for the first time, I expressed boolean type wi th the symbol "bool", instead of "BOOL". This error is what I have never expected before.

    Friday, August 23, 2013 7:34 AM

Answers

  • bool is correct, what's incorrect is writing a function outside of a class/struct, you cannot have global functions in C#.
    Friday, August 23, 2013 7:39 AM
    Moderator
  • Hi,

    you need to provide a type that will further encapsulate any function like this:

    class A { public bool CheckNumber(string strText)

    {

    ....

    return true;

    } }


    I hope this may help.


    One good question is equivalent to ten best answers.

    Friday, August 23, 2013 9:46 AM

All replies

  • bool is correct, what's incorrect is writing a function outside of a class/struct, you cannot have global functions in C#.
    Friday, August 23, 2013 7:39 AM
    Moderator
  • Hi,

    you need to provide a type that will further encapsulate any function like this:

    class A { public bool CheckNumber(string strText)

    {

    ....

    return true;

    } }


    I hope this may help.


    One good question is equivalent to ten best answers.

    Friday, August 23, 2013 9:46 AM
  • Thank you for kind comment. But the function I composed was a member function of a class. I will try again. Thanks , anyway.
    Saturday, August 24, 2013 5:01 AM
  • Then try posting the class too. I'd keep an eye on braces, it's relatively easy to have a stray } somewhere that closes the class and leaves the method outside.
    Saturday, August 24, 2013 8:11 AM
    Moderator