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 736275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:35:09+00:00 2026-05-14T07:35:09+00:00

I have an IPAddress class which has one property named ip and in its

  • 0

I have an IPAddress class which has one property named ip and in its setter I am validating data coming and if data is invalid it throws an error. (Its code is as the following):

private string ip;

public string IP
{
  get { return ip; }
  set { string PartsOfIP = value.Split('.');

  if (PartsOfIP.Length == 4)
  {
    foreach (string part in PartsOfIP)
     { int a = 0; bool result = int.TryParse(part, out a);

        if (result != true)
        {
          throw new Exception("Invalid IP");

        }
        else { ip = value; }
      }

  }
  else { throw new Exception("Invalid IP");
  }
}

In User Class I want to compose an object of IPAddress class.

I am doing validations for properties of User in User class and validations of Ip in IPAddress class.

My question is how I will compose IPAddress object in UserClass and what will be syntax for this ?

If I again mention get and set here with IPAddress object in User class will my earlier mentioned (in IPAddress class) getter and setter work ?

  • 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-05-14T07:35:10+00:00Added an answer on May 14, 2026 at 7:35 am
    1. Create constructor for UserClass like this:

      public IPAddress userIpAddress;
      // Other fields and properties
      
      public UserCLass(IPAddress ipAddress, .... other fields)
      {
          userIpAddress = ipAddress; // here validation for IPAddress will be called
      }
      
    2. Use regular expressions for IPAddress validation

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the a class in my application. It has been bound to winform
I have generic async task class which fetches response from server . And i
I have a Class library application in which I'm trying to use SSL connection.
With Django I have this model: class downloads(models.Model): date = models.CharField(max_length=50) ip = models.ForeignKey(IPaddress)
I have a class IPAddressString that has: a private field of type String called
I have an asynchronous UDP server class with a socket bound on IPAddress.Any, and
I want to have a collection of objects, which will be of a class
I have an extension class for System.Net.IPAddress and I was wanting to overload the
I have an IAddress class with a few properties. I then have a concrete
I have the following classes in my models file class HardwareNode(models.Model): ip_address = models.CharField(max_length=15)

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.