Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9059845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:04:27+00:00 2026-06-16T15:04:27+00:00

My class inherits an interface so I need to have the emailaddress property in

  • 0

My class inherits an interface so I need to have the emailaddress property in the Person class.

My question is what is the best way to get the property and set the property

public class Contact : IPerson, ILocation
{
  ...
  [MaxLength(256)]
  public string EmailAddress { 
  get{
    return this.Emails.First().ToString();
  } 
  set{ ????  }
  }
  ....

  public virtual ICollection<Emails> Emails { get; set; }
}

Essentially, I’m trying to get the class to allow more than one email.

For full disclosure, I’m pretty new to this and I may not be asking the correct questions, but I’ve searched for a day and half and haven’t seen anything like this (not that I think it’s unusual) and could use the insight.

Email class properties:

[Key]
public int Id { get; set; }

[MaxLength(256)]
    public string EmailAddress { get; set; }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:04:28+00:00Added an answer on June 16, 2026 at 3:04 pm

    Do you have control over the design of the IPerson interface that is forcing you to implement EmailAddress? If so, I would recommend rethinking the design to avoid needing both a singular property and a list of email addresses on the same object.

    You may also want to consider making the Emails property setter protected, to prevent outside code from changing your object’s data.

    If you must implement to this interface, and you wish to have the EmailAddress property always refer to the first email in the collection, you can try this code.

    public class Contact : IPerson, ILocation
    {
      public Contact()
      {
        // Initialize the emails list
        this.Emails = new List<Emails>();
      }
    
      [MaxLength(256)]
      public string EmailAddress
      { 
        get
        {
          // You'll need to decide what to return if the first email has not been set.
          // Replace string.Empty with the appropriate value.
          return this.Emails.Count == 0 ? string.Empty : this.Emails[0].ToString();
        } 
        set
        {
          if (this.Emails.Count == 0)
          {
            this.Emails.Add(new Emails());
          }
          this.Emails[0].EmailAddress = value;
        }
      }
    
      public virtual IList<Emails> Emails { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is .NET 4.0/C#. I have a class that inherits from an interface: public
I have a class Animal and an interface it inherits from IAnimal. @MappedSuperclass public
I have the following dependency property in my MainWindow class (inherits from WPF's Window)
using an interface (abstract class) on c++ i have the need to force any
Probably a simple question. I have an interface (MyInterface) that defines a property like
I have a class that inherits a generic dictionary and an inteface public class
If a class inherits from an interface that itself implements IDisposable should that class
I've got a class that inherits from an interface. That interface defines an event
If we have a class that inherits from multiple interfaces, and the interfaces have
Since every class inherits the initializer from the superclass this is how I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.