• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

need to create a custom class called Address.cs. I have done some things. Need someone to check it out.

I need someone to check if this is ok for a profile

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for Address
/// </summary>
[Serializable()]
public class Address
{
    public Address() {  }
   
    public Address
    (
        string country,
        string region,
        string city,
        string zipcode)
    {
        this.Country = country;
        this.Region = region;
        this.City= city;
        this.ZipCode = zipcode;
       
    }

    private string country = "";
    public string Country
    {
        get { return country; }
        set { country = value; }
    }

    private string region = "";
    public string Region
    {
        get { return region; }
        set { region = value; }
    }

    private string city = "";
    public string City
    {
        get { return city; }
        set { city = value; }
    }

    private string zipcode = "";
    public string ZipCode
    {
        get { return zipcode; }
        set { zipcode = value; }
    }
}
0
mathieu_cupryk
Asked:
mathieu_cupryk
2 Solutions
 
nmarunCommented:
Looks about right. You can instantiate this class as follows:

Address address = new Address(country, region, city, zipcode);
 
or as 
 
Address address = new Address();
address.Country = country;
address.Region = region;
address.City = city;
address.ZipCode = zipcode;

Open in new window

0
 
jabcocoCommented:
If using .NET 3.5 you can use this.

//Declare you class object with properties
-----------------------------------------------
public class MyClass
{
    public string LastName { get; set; }
    public string FirstName { get; set; }
 
    public MyClass(){}
}
 
//Create a new instance of the MyClass object
-----------------------------------------------
MyClass oMc = new MyClass(){
    LastName = "MyLastName",
    FirstName = "MyFirstName"
};

Open in new window

0
 
mathieu_cuprykAuthor Commented:
how does this look?
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for Address
/// </summary>
[Serializable()]
public class Address
{
    public Address() {  }
   
    public Address
    (
        string country,
        string region,
        string city,
        string zipcode)
    {
        this.Country = country;
        this.Region = region;
        this.City= city;
        this.ZipCode = zipcode;
       
    }

    private string country = "";
    public string Country { get; set; }

    private string region = "";
    public string Region { get; set; }

    private string city = "";
    public string City { get; set; }

    private string zipcode = "";
    public string ZipCode { get; set; }

}
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now