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

C# Error

CS1938 – The name ‘{0}’ is not in scope on the right 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 right 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 code generates CS1938:

// cs1938.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 // CS1938  
                    // Try the following line instead.  
                    // join b in sourceB on a equals b  
                    select new { a, b };  
    }  
}  

Leave A Reply

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

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...