How do I combine enumerated constants?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christian Blackburn

    How do I combine enumerated constants?

    Hi Gang,

    I'm a long time VB programmer and in that language I now how to
    combine constants. Can somebody give me the correct syntax for
    combining constants in C# for the following dialog:

    using Microsoft.Visua lBasic;

    Interaction.Msg Box("Can you even see the form yet?",
    (MsgBoxStyle.Qu estion | MsgBoxStyle.OkO nly), "Debug");

    Thanks I know this is easy, but heh I'm a noob.

    Thanks,
    Christian

  • Peter Duniho

    #2
    Re: How do I combine enumerated constants?

    On Sat, 12 Jul 2008 22:57:10 -0700, Christian Blackburn
    <christian.Blac kburn@yahoo.com wrote:
    I'm a long time VB programmer and in that language I now how to
    combine constants. Can somebody give me the correct syntax for
    combining constants in C# for the following dialog:
    >
    using Microsoft.Visua lBasic;
    >
    Interaction.Msg Box("Can you even see the form yet?",
    (MsgBoxStyle.Qu estion | MsgBoxStyle.OkO nly), "Debug");
    >
    Thanks I know this is easy, but heh I'm a noob.
    I don't understand the question. What's not working about the code you
    posted?

    Comment

    • Christian Blackburn

      #3
      Re: How do I combine enumerated constants?

      Hi Peter,

      Thanks for helping.
      I don't understand the question.  What's not working about the code you 
      posted?
      Specifically I can't combine the styles question and OkOnly below:
      (MsgBoxStyle.Qu estion | MsgBoxStyle.OkO nly)

      Thanks,
      Christian

      Comment

      • Marc Gravell

        #4
        Re: How do I combine enumerated constants?

        Except that you have! The code works fine for me... I get a message
        box with just an OK, and a question. Note that you need to do this in
        a method (here I've used the Main entry-point), otherwise you get the
        error "A namespace does not directly contain members such as fields or
        methods".

        (note: asking a question with only one possible answer [other than
        closing the form] might seem unusual...)

        using Microsoft.Visua lBasic;
        static class Program
        {
        static void Main()
        {
        Interaction.Msg Box("Can you even see the form yet?",
        MsgBoxStyle.Que stion | MsgBoxStyle.OkO nly, "Debug");
        }
        }

        Note that you can drop the VB reference and use the main framework
        version:

        using System.Windows. Forms;
        static class Program
        {
        static void Main()
        {
        MessageBox.Show ("Can you even see the form yet?", "Debug",
        MessageBoxButto ns.OK, MessageBoxIcon. Question);
        }
        }

        Marc

        Comment

        • Christian Blackburn

          #5
          Re: How do I combine enumerated constants?

          Hi Marc,

          Thanks for all the help, I appreciate knowing how to combine constants
          and do it the .net native way, because frankly the VB way was a pain
          Interaction.Msg Box is certainly more than I want to type. Sometimes
          object oriented programming sucks, with all that extra typing. I will
          do it the native way from now on MessageBox.Show .

          Thanks,
          Christian

          Comment

          • Marc Gravell

            #6
            Re: How do I combine enumerated constants?

            with all that extra typing
            Well, 3 characters on the method call, but actually the VB way is
            probably less chars overall, thanks to the length of MessageBoxButto ns
            and MessageBoxIcon

            Of course, intellisense to the rescue, with [tab] auto-completion, or
            alternatively the "mbox" snippet (type mbox[tab][tab]).

            Marc

            Comment

            • Christian Blackburn

              #7
              Re: How do I combine enumerated constants?

              Hi Marc,

              I really like the mbox thing, while I get I can make my own snippets,
              do you know of a website that lists the most common built in
              snippets?

              Thanks,
              Christian

              Comment

              • Marc Gravell

                #8
                Re: How do I combine enumerated constants?

                You can look at them in the IDE, or at least you can in VS2008 (I don't
                have 2005 to hand)...

                To be honest, the most common one I use is "svm" (static void Main) -
                while setting up throw-away test projects ;-p
                If you do a lot of WF / WPF then the attached/dependency properties
                ["propa"/"propdp"] might be handy - but in most cases I find it easier
                to just type ;-p

                Back in C# 2, arguably the "prop" snippet was useful, but not so much in
                C# 3. And I have a bespoke "nonull" - but again, most often I just type
                the code I want.

                Tools =Code Snippets Manager [Ctrl]+K, [Ctrl]+B.

                Marc

                Comment

                • Christian Blackburn

                  #9
                  Re: How do I combine enumerated constants?

                  Hi Marc,
                  You can look at them in the IDE, or at least you can in VS2008 (I don't
                  have 2005 to hand)...
                  Yes, I'm still kicking it with 2005 (I don't use new programming
                  languages and new applications in general, I like letting other people
                  find/fix the bugs, I'll come along when it's stable).
                  >
                  To be honest, the most common one I use is "svm" (static void Main) -
                  while setting up throw-away test projects ;-p
                  If you do a lot of WF / WPF then the attached/dependency properties
                  ["propa"/"propdp"] might be handy - but in most cases I find it easier
                  to just type ;-p
                  Hey those are great, but I didn't notice any difference between propa
                  and propdp, am I missing something?.
                  Back in C# 2, arguably the "prop" snippet was useful, but not so much in
                  C# 3. And I have a bespoke "nonull" - but again, most often I just type
                  the code I want.
                  That's fine when you really know what you're doing :). I'm not there
                  yet :).
                  >
                  Tools =Code Snippets Manager [Ctrl]+K, [Ctrl]+B.
                  Oh boy! There's a ton of them, that's terrific. I really like
                  that.
                  Marc
                  Thanks,
                  Christian

                  Comment

                  Working...