I am fairly new to C#, OOP, and forms. I am using Visual Studio 2008. I need to for an assignment create an "Address" that has the following fields: Street, City, State, and Zip Code. Then I need to create a web form which enters info into the "Address" class, which prints a mailing address. I thought the main program creates an instance of a class, not writing into a class, am I misunderstanding what he is saying? Please let me know how would go about doing something like this.
Below is the "Address" class, or should I just say just the fields.
|
Jaish MathewsPosted Apr 12, 2010, 2:26 AM
No need. VS 2008 supporting these type of property definition. Local variables declarations all those will be taken care internally.
Jordan McGeheePosted Apr 11, 2010, 4:56 PM
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
///
/// Summary description for Address
///
public class Address
{
private string street;
private string city;
private string state;
private string zipCode;
public string Street
{
get
{
return street;
}
set
{
street = value;
}
}
public string City
{
get
{
return city;
}
set
{
city = value;
}
}
public string State
{
get
{
return state;
}
set
{
state = value;
}
}
public string ZipCode
{
get
{
return zipCode;
}
set
{
zipCode = value;
}
}
public Address()
{
}
}
Jaish MathewsPosted Apr 11, 2010, 11:19 AM
Create a searate project named something like "EntityItems". Create the Address class under this project. If you have any other class like Employee also create under this project. We needs to layer the aplication like this based on need. Below the basic structure of your class. You should use properties for representing fields. They ensuring encapsulation, as only returing the value of the field through properties. Not touching real data.
public class Address
{
public string Street
{
get;
set;
}
public string City
{
get;
set;
}
public string State
{
get;
set;
}
public string ZIPCode
{
get;
set;
}