C# How do I check if one of two values is TRUE?

后端 未结 8 1505
梦毁少年i
梦毁少年i 2021-01-12 13:24

Should be a simple question for the C# experts here.

I basically want to check if one value or another is TRUE, a wild stab at the code is below:

if          


        
8条回答
  •  囚心锁ツ
    2021-01-12 13:45

    This is a similar scenario but I am checking for three or more bool values.

    Thread th = new Thread(() =>
                    {
                        while (true)
                        {
                            bool allReadComplete = true;
    
                            foreach (IDataProvider provider in lstDataProviders)
                            {
                                provider.StartReading();
    
                                if (provider.FinishedReading)
                                  allReadComplete = allReadComplete && provider.FinishedReading;
                                else
                                  allReadComplete = provider.FinishedReading;
                            }
    
                            // to induce some context switching
                            Thread.Sleep(0);
    
                            if (allReadComplete)
                                break;
                        }
    
                        Console.WriteLine("Thread Exiting");
    
                    });
                th.IsBackground = true;
                th.Start();
    

提交回复
热议问题