HomeCSharpC# Error CS0704 – Cannot do non-virtual member lookup in ‘{0}’ because it is a type parameter

C# Error CS0704 – Cannot do non-virtual member lookup in ‘{0}’ because it is a type parameter

C# Error

CS0704 – Cannot do non-virtual member lookup in ‘{0}’ because it is a type parameter

Reason for the Error & Solution

Cannot do member lookup in ‘type’ because it is a type parameter

An inner type cannot be specified through a type parameter. Try using the desired type explicitly.

Example

The following sample generates CS0704:

// CS0704.cs  
class B  
{  
    public class I { }  
}  
  
class C<T> where T : B  
{  
    T.I f;  // CS0704 – member lookup on type parameter  
    // Try this instead:  
    // B.I f;  
}  
  
class CMain  
{  
    public static void Main() {}  
}  

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