HomeCSharpC# Error CS1948 – The range variable ‘{0}’ cannot have the same name as a method type parameter

C# Error CS1948 – The range variable ‘{0}’ cannot have the same name as a method type parameter

C# Error

CS1948 – The range variable ‘{0}’ cannot have the same name as a method type parameter

Reason for the Error & Solution

The range variable ‘name’ cannot have the same name as a method type parameter

The same declaration space cannot contain two declarations of the same identifier.

To correct this error

  1. Change the name of the range variable or the type parameter.

Example

The following example generates CS1948 because the identifier T is used for the range variable and for the type parameter on method TestMethod:

// cs1948.cs  
using System.Linq;  
class Test  
{  
    public void TestMethod<T>(T t)  
    {  
        var x = from T in Enumerable.Range(1, 100) // CS1948  
                select T;  
    }  
}  

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...