Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent a method from accepting 2 false bool in C# .NET?

I have a method with this signature:

public static void DirFillWEx(ComboBox cb, bool dirFill, bool fileFill);

this is put in a dll library I wrote myself. My question is: is there a way to instruct Visual Studio that this method cannot accept both the bool values as false, so I get an error at compile time (NOT RUNTIME!)?

For Example:

DirFillWEx(my_cb, false, true);
DirFillWEx(my_cb, true, true);
DirFillWEx(my_cb, true, false);

but not

DirFillWEx(my_cb, false, false);

Thank you all!

like image 525
Ale TheFe Avatar asked Dec 05 '25 14:12

Ale TheFe


1 Answers

You could define an enum:

enum FillMode
{
  Dir,
  File,
  Both
}

and then type your method to take the enum:

public static void DirFillWEx(ComboBox cb, FillMode fillMode);
like image 178
Sean Avatar answered Dec 08 '25 03:12

Sean



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!