Question

I'm converting vb code to c#

There is enum from telerik library:

namespace Telerik.Windows.Controls
{
    // Summary:
    //     Provides flags for enumerating the ViewModes supported by Telerik.Windows.Controls.RadScheduler.
    [Flags]
    public enum AvailableViewModes
    {
        // Summary:
        //     Enables Day view.
        Day = 1,
        //
        // Summary:
        //     Enables Week view.
        Week = 2,
        //
        // Summary:
        //     Enables Month view.
        Month = 4,
        //
        // Summary:
        //     Enables Timeline view.
        Timeline = 8,
        //
        // Summary:
        //     Enables All views.
        All = 15,
    }
}

and code in vb is

cal.AvailableViewModes = cal.AvailableViewModes And Not AvailableViewModes.All

Converter returns me

cal.AvailableViewModes = cal.AvailableViewModes & !AvailableViewModes.All

and it's not correct because cannot applu operator ! to opperand of this enum.

Was it helpful?

Solution

The bitwise not operator is ~.

OTHER TIPS

Use the ~ operator to flip the bits.

Try the following instead

cal.AvailableViewModes = cal.AvailableViewModes & (~AvailableViewModes.All)

The converter is having a problem here because Not in VB.Net has two purposes: Boolean and bitwise. Which version is used depends on the type of the expression being targeted. Since Not is being used on a numeric value in the VB.Net code it's actually using the bitwise version. In C# the ~ operator is the equivalent.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top