i'be looked some same topics but havn't find what i'm looking for I should use flag enum flag atribute and check if my data is in one of the collections of this enum For example, enum:  [Flags] private enum MyEnum { Apple, Orange, Tomato, Potato Melon, Watermelon,  Fruit = Apple | Orange, Vegetable = Tomato | Potato, Berry = Melon | Watermelon, }   In the method i should check a input data. How can i do it?   private void Checking(string data){ if(MyEnum.Fruit contains data) MessageBox.Show("Fruit"); if(MyEnum.Vegetable contains data) MessageBox.Show("Vegetables"); if(MyEnum.Berry contains data) MessageBox.Show("Berry"); }   What should be instead of "contains data"?  UPDATE  private void ZZZ(){ Cheching("Apple"); }
527
From time to time I see an enum like the following:  [Flags] public enum Options  {     None    = 0,     Option1 = 1,     Option2 = 2,     Option3 = 4,     Option4 = 8 }   I don't understand what exactly the [Flags] attribute does.  Anyone have a good explanation or example they could post?
122930
I'm comparing two list given in the list to see if the item.name exists in both for loop. If not then add into a list to show the error for the missing names.  set&lt;id&gt; setAssetIds = new set&lt;id&gt;(); list&lt;Asset_Store__c&gt;  assets = [select id,name......]; for(Asset_Store__c item : assets ) {     setAssetIds.add(item.id);  }   list&lt;Meter__c&gt;  meters = [select id,name......where id in : setAssetIds];  //now comparing the two lists for(Asset_Store__c a : assets) {    for(Meter__c m : meters)    {      if(a.Name != m.Name)      {        //not matched...        break;      }     } }   the problem with the above approach is that, its not finding the correct name.
53945
I've got an enum like this:  public enum MyLovelyEnum {     FirstSelection,     TheOtherSelection,     YetAnotherOne };   I got a property in my DataContext:  public MyLovelyEnum VeryLovelyEnum { get; set; }   And I got three RadioButtons in my WPF client.  &lt;RadioButton Margin="3"&gt;First Selection&lt;/RadioButton&gt; &lt;RadioButton Margin="3"&gt;The Other Selection&lt;/RadioButton&gt; &lt;RadioButton Margin="3"&gt;Yet Another one&lt;/RadioButton&gt;   Now how do I bind the RadioButtons to the property for a proper two-way binding?
7172
What would be the best way to look in a string[] to see if it contains a element. This was my first shot at it. But perhaps there is something that I am overlooking. The array size will be no larger than 200 elements.  bool isStringInArray(string[] strArray, string key) {     for (int i = 0; i &lt;= strArray.Length - 1; i++)         if (strArray[i] == key)             return true;     return false; }
102005
Is there a way in JPA to map a collection of Enums within the Entity class? Or the only solution is to wrap Enum with another domain class and use it to map the collection?  @Entity public class Person {     public enum InterestsEnum {Books, Sport, etc...  }     //@???     Collection&lt;InterestsEnum&gt; interests; }   I am using Hibernate JPA implementation, but of course would prefer implementation agnostic solution.
31086
I have a generic method defined like this:  public void MyMethod&lt;T&gt;(T myArgument)   The first thing I want to do is check if the value of myArgument is the default value for that type, something like this:  if (myArgument == default(T))   But this doesn't compile because I haven't guaranteed that T will implement the == operator.  So I switched the code to this:  if (myArgument.Equals(default(T)))   Now this compiles, but will fail if myArgument is null, which is part of what I'm testing for.  I can add an explicit null check like this:  if (myArgument == null || myArgument.Equals(default(T)))   Now this feels redundant to me.  ReSharper is even suggesting that I change the myArgument == null part into myArgument == default(T) which is where I started.  Is there a better way to solve this problem?  I need to support both references types and value types.
63512
Am not doing anything fancy, just trying to use  method of list.      List&lt;Id&gt; myIdList = new List&lt;Id&gt;(); myIdList.add('0060E000008PdMk');  Id oppId ='0060E000008PdMk';      System.debug(myIdList.contains(oppId)); //Returns false   To my surprise, I spent a few hours debugging and came with this problematic code. Are we not supposed to use contains for List&lt;Id&gt; ?  Changing the type from List&lt;Id&gt; to List&lt;String&gt; makes my code run, but I dont have any clue why it does?   Can anyone shed some light?  UPDATE : As per the suggestion of sfdcfox I have raised a case with SF support. Case number "19522568". I will keep you guys updated with the results.  UPDATE 2 : Salesforce reached out to me for this,   A bug W-4884673 already exist for this issue. SF R&amp;D team is working on the same. Known issue link for reference:   There isn't any ETA for this to be fixed, so the case will be closed as "bug fix submitted"  UPDATE 3 : This has now been resolved
114921
I have some code like this:  If key.Equals("search", StringComparison.OrdinalIgnoreCase) Then     DoSomething() End If   I don't care about the case. Should I use OrdinalIgnoreCase, InvariantCultureIgnoreCase, or CurrentCultureIgnoreCase?
116653
I have this:  If String.IsNullOrEmpty(editTransactionRow.pay_id.ToString()) = False Then     stTransactionPaymentID = editTransactionRow.pay_id 'Check for null value End If   Now, when editTransactionRow.pay_id is Null Visual Basic throws an exception. Is there something wrong with this code?
96218
I came across this code and wanted others to provide their point of view... is it good or bad ? ;)  Class ReportClass {  public string ReportName {get; set;} }   Then it was used as follows in code:  displayReport(ReportClass.ReportName = cmbReportName.SelectedValue.ToString())   That is about the simplest form example I can give you. Quetion is... why can't I find examples ? What would this be called? Is this just asking for trouble?  EDIT: I'm referring to the inplace assignment. Which I wasn't aware of until today
67578
I haven't written any C++ in years and now I'm trying to get back into it. I then ran across this and thought about giving up:  typedef enum TokenType {     blah1   = 0x00000000,     blah2   = 0X01000000,     blah3   = 0X02000000 } TokenType;   What is this? Why is the typedef keyword used here? Why does the name TokenType appear twice in this declaration? How are the semantics different from this:  enum TokenType {     blah1 = 0x00000000,     blah2=0x01000000,     blah3=0x02000000 };
12013
I've the enum type ReportTypeEnum that get passed between methods in all my classes but I then need to pass this on the URL so I use the ordinal method to get the int value. After I get it in my other JSP page, I need to convert it to back to an ReportTypeEnum so that I can continue passing it.   How can I convert ordinal to the ReportTypeEnum?  Using Java 6 SE.
122980
This is my code:  internal enum WindowsMessagesFlags {     WM_EXITSIZEMOVE      = 0x00000232,     WM_DISPLAYCHANGE     = 0x0000007e,     WM_MOVING            = 0x00000216, }  protected override void WndProc(ref Message m) {     switch(m.Msg) {         case (int)WindowsMessagesFlags.WM_DISPLAYCHANGE:             FixWindowSnapping();             break;         case (int)WindowsMessagesFlags.WM_EXITSIZEMOVE:             SaveWindowProperties();             break;         case (int)WindowsMessagesFlags.WM_MOVING:             KeepProperLocation(ref m);             break;     } }   Is there anyway to prevent the casting?
32814
Here's what I am trying to do:    typedef enum { ONE, TWO, THREE } Numbers;   I am trying to write a function that would do a switch case similar to the following:   char num_str[10]; int process_numbers_str(Numbers num) {   switch(num) {     case ONE:     case TWO:     case THREE:     {       strcpy(num_str, num); //some way to get the symbolic constant name in here?     } break;     default:       return 0; //no match   return 1; }   Instead of defining at every case, is there a way to set it using the enum variable like I am trying to do above?
22847
Suppose we have some named enums:  enum MyEnum {       FOO,       BAR = 0x50 };   What I googled for is a script (any language) that scans all the headers in my project and generates a header with one function per enum.  char* enum_to_string(MyEnum t);   And a implementation with something like this:  char* enum_to_string(MyEnum t){       switch(t){          case FOO:             return "FOO";          case BAR:             return "BAR";          default:             return "INVALID ENUM";       }  }   The gotcha is really with typedefed enums, and unnamed C style enums. Does anybody know something for this?  EDIT: The solution should not modify my source, except for the generated functions. The enums are in an API, so using the solutions proposed until now is just not an option.
63397
I'm always surprised that even after using C# for all this time now, I still manage to find things I didn't know about...  I've tried searching the internet for this, but using the "~" in a search isn't working for me so well and I didn't find anything on MSDN either (not to say it isn't there)  I saw this snippet of code recently, what does the tilde(~) mean?  /// &lt;summary&gt; /// Enumerates the ways a customer may purchase goods. /// &lt;/summary&gt; [Flags] public enum PurchaseMethod {        All = ~0,     None =  0,     Cash =  1,     Check =  2,     CreditCard =  4 }   I was a little surprised to see it so I tried to compile it, and it worked... but I still don't know what it means/does. Any help??
37598
After two years of C#, I'm now back to VB.net because of my current job. In C#, I can do a short hand testing for null or false value on a string variable like this:  if(!String.IsNullOrEmpty(blah)) {    ...code goes here }   however I'm a little confused about how to do this in VB.net.  if Not String.IsNullOrEmpty(blah) then    ...code goes here end if   Does the above statement mean if the string is not null or empty? Is the Not keyword operate like the C#'s ! operator?