interlock exchange issue

This is a discussion on interlock exchange issue within the C# Programming forums, part of the General Programming Boards category; Hello everyone, How to fix the compile error when interlock exchange a bool type variable? Code: public static void Main() ...

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    interlock exchange issue

    Hello everyone,


    How to fix the compile error when interlock exchange a bool type variable?

    Code:
        public static void Main()
        {
            bool b = false;
    
            // error CS0452: The type 'bool' must be a reference type in order to use it as parameter
            // 'T' in the generic type or method 'System.Threading.Interlocked.Exchange<T>(ref T, T)'
            bool a = Interlocked.Exchange(ref b, true);
    
            return;
        }

    thanks in advance,
    George

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    The MSDN examples state that you should be using an int instead. While this is also a non-referencetype, there are overloads of Exchange for int.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. float calculation issue
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-26-2008, 04:56 AM
  2. MS Exchange Calender access
    By maes in forum Windows Programming
    Replies: 2
    Last Post: 07-17-2004, 02:17 AM
  3. Recovery Exchange 2000 Public folders?!?!
    By gicio in forum Tech Board
    Replies: 4
    Last Post: 10-01-2003, 07:48 AM
  4. Replies: 8
    Last Post: 09-22-2003, 01:31 PM
  5. Connect 2 domains together (with Windows 2003 and Exchange 2003)?!?!??
    By gicio in forum Networking/Device Communication
    Replies: 2
    Last Post: 09-01-2003, 07:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21