I'm having trouble with C# auto implementing the 'NotImplementedException' to the auto-implemented properties whenever I generated them.
This is the interface class :
public interface IPerson
{
string Name {get;set;}
int Age {get; set;}
char Gender {get; set;}
string Email {get;set;}
string Address {get;set;}
}
This is the derived class. It's auto-implementing 'NotImplementedException' method whenever I tried to implement the interface to the derived class.
public class Student : IPerson
{
public Student()
{
}
public string Name { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public int Age { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public char Gender { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string Email { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
public string Address { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
}
Is there a way to make that the accessor methods in Student class is not auto-implemented with 'NotImplementedException' when I implement and generated the members from the IPerson interface ?
CodePudding user response:
Selecting prefer auto properties
will implement properties in interfaces with just get
or set
instead of throwing NotImplementedException
s
This is what the setting looks like in VS 2022