HomeCSharpC# Error CS1937 – The name ‘{0}’ is not in scope on the left side of ‘equals’. Consider swapping the expressions on either side of ‘equals’.

C# Error CS1937 – The name ‘{0}’ is not in scope on the left side of ‘equals’. Consider swapping the expressions on either side of ‘equals’.

C# Error

CS1937 – The name ‘{0}’ is not in scope on the left side of ‘equals’. Consider swapping the expressions on either side of ‘equals’.

Reason for the Error & Solution

The name ‘name’ is not in scope on the left side of ‘equals’. Consider swapping the expressions on either side of ‘equals’.

The equals keyword is a special operator that is used in a join clause to determine equality between two expressions. The range variable for the left side source sequence is in scope on the left side of equals, and the range variable for the right side source is only in scope on the left side of equals. You can verify this by experimenting with IntelliSense in the following code example.

To correct this error

  1. Swap the position of the two range variables as shown in the commented line in the following example:

Example

The following example generates CS1937.

// cs1937.cs  
using System.Linq;  
class Test  
{  
    static void Main()  
    {  
        int[] sourceA = { 1, 2, 3, 4, 5 };  
        int[] sourceB = { 3, 4, 5, 6, 7 };  
  
        var query = from a in sourceA  
                    join b in sourceB on b equals a // CS1937  
                    // Try the following line instead.  
                    //join b in sourceB on a equals b  
                    select new { a, b };  
    }  
}  

The left side is generally called the "outer" side and the right is generally called the "inner" side.

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...