代码(〜)在.NET中代表什么?即currentStyle&=〜(int)(WindowStyles.WS_BORDER);

use*_*634 0 .net c#

我是一名VB开发人员,目前正在破译用C#编写的应用程序.一般来说,我可以通过谷歌找到答案.但我迷失了.C#中使用的波浪号(〜)是多少?

这是一个包含表达式的剪辑:

  /// <summary>
        /// Updates the window style for the parent form.
        /// </summary>
        private void UpdateStyle()
        {
            // remove the border style
            Int32 currentStyle = Win32Api.GetWindowLong(Handle, GWLIndex.GWL_STYLE);
            if ((currentStyle & (int)(WindowStyles.WS_BORDER)) != 0)
            {
                currentStyle &= ~(int) (WindowStyles.WS_BORDER);
                Win32Api.SetWindowLong(_parentForm.Handle, GWLIndex.GWL_STYLE, currentStyle);
                Win32Api.SetWindowPos(_parentForm.Handle, (IntPtr) 0, -1, -1, -1, -1,
                                      (int) (SWPFlags.SWP_NOZORDER | SWPFlags.SWP_NOSIZE | SWPFlags.SWP_NOMOVE |
                                             SWPFlags.SWP_FRAMECHANGED | SWPFlags.SWP_NOREDRAW | SWPFlags.SWP_NOACTIVATE));
            }
        }
Run Code Online (Sandbox Code Playgroud)

Pin*_*nyM 5

它是按位NOT运算符.

在这种情况下,以下代码:

currentStyle &= ~(int) (WindowStyles.WS_BORDER);
Run Code Online (Sandbox Code Playgroud)

可以解释为:将WindowStyles.WS_BORDER枚举转换为a int,取逆位(使用~运算符)并将它们与currentStyle使用中保持的值合并&(按位AND).最后,将结果存储回currentStyle变量.