How do I combine enumerated constants?

  • Thread starter Thread starter Christian Blackburn
  • Start date Start date
C

Christian Blackburn

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.VisualBasic;

Interaction.MsgBox("Can you even see the form yet?",
(MsgBoxStyle.Question | MsgBoxStyle.OkOnly), "Debug");

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

Thanks,
Christian
 
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.Question | MsgBoxStyle.OkOnly)

Thanks,
Christian
 
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.VisualBasic;
static class Program
{
static void Main()
{
Interaction.MsgBox("Can you even see the form yet?",
MsgBoxStyle.Question | MsgBoxStyle.OkOnly, "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",
MessageBoxButtons.OK, MessageBoxIcon.Question);
}
}

Marc
 
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.MsgBox 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
 
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 MessageBoxButtons
and MessageBoxIcon

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

Marc
 
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
 
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
 
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.

Thanks,
Christian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top