C# Error CS0175 – Use of keyword ‘base’ is not valid in this context

C# Compiler Error

CS0175 – Use of keyword ‘base’ is not valid in this context

Reason for the Error

You will receive this error when you have used the base keyword without specifying any member of the base class.

For example, try compiling the below code snippet

namespace ConsoleApp3
{
    using System;
    class BaseEmployee
    {
        public int Id = 0;
    }

    class Employee : BaseEmployee
    {
        public void DisplayEmployeeId()
        {
			// CS0175 
            Console.WriteLine(base);           
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Employee aClass = new Employee();
            aClass.DisplayEmployeeId();
        }
    }
}

The above code snippet will result with the error code CS0175

Error CS0175 Use of keyword ‘base’ is not valid in this context ConsoleApp3 C:\Users\Senthil\source\repos\ConsoleApp3\ConsoleApp3\Program.cs 13 Active

Solution

To fix this error, ensure that you specify the member of the base class when you use the base keyword. For example, the above code can be fixed by replacing the DisplayEmployeeId function with the below code snippet.

public void DisplayEmployeeId()
{
	Console.WriteLine(base.Id);

}

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