I am trying to use a set of conditional statements that will set up an enumeration attributed with [Flags]. However, the compiler complains that ‘m’ is unassigned. How can I rewrite the following to achieve my intended functionality?
Media m; if (filterOptions.ShowAudioFiles) m = m | Media.Audio; if (filterOptions.ShowDocumentFiles) m = m | Media.Document; if (filterOptions.ShowImageFiles) m = m | Media.Image; if (filterOptions.ShowVideoFiles) m = m | Media.Video;
You need to initialize m. Create a ‘None’ flag that has value 0 then:
Then the rest of your code.