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

时间:2014-04-14 03:19:12

标签: c# .net

我是一名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));
            }
        }

1 个答案:

答案 0 :(得分:5)

这是bitwise NOT operator

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

currentStyle &= ~(int) (WindowStyles.WS_BORDER);

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