What is the purpose of IsFinal property in C# Reflection?

 Posted by Rajnilari2015 on 9/22/2015 | Category: C# Interview questions | Views: 1656 | Points: 40

The IsFinal property of MethodBase class gets a value indicating whether this method is final.It returns true if this method is final; otherwise, false. It is defined as
public bool IsFinal { get; }


Suppose we have

public class Employee : IMyInterface

public int property1 { get; set; }
public int EmployeeId { get; set; }
public string EmployeeName { get; set; }
public virtual int EmployeeAge { private set; get; } //read-only property
public virtual string EmployeeSalary { set; private get; } //write-only property

interface IMyInterface
int property1 { get; set; }


And we want to get only the interface property name. Use the below code

.Where(p => p.GetAccessors()[0].IsFinal)
.ForEach(i => Console.WriteLine(i.Name));

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response