类的创建
class Customer
{
public string name;
public string address;
public int age;
public string buyTime;
public void Show ( )
{
Console. WriteLine ( "姓名" + name) ;
Console. WriteLine ( "address" + address) ;
Console. WriteLine ( "age" + age) ;
Console. WriteLine ( "buyTime" + buyTime) ;
}
}
创建对象
Customer customer_1;
customer_1 = new Customer ( ) ;
customer_1. name = "langlang" ;
Console. WriteLine ( customer_1. name) ;
customer_1. Show ( ) ;
Console. ReadKey ( ) ;
再写一个
namespace Learn_class
{
class Vehicle
{
public float speed;
public float maxSpeed;
public float weight;
public float x, y, z;
public void Run ( )
{
Console. WriteLine ( "vehicle is running!" ) ;
}
public void Stop ( )
{
Console. WriteLine ( "vehicle is stop" ) ;
speed = 0 ;
}
public float Length ( )
{
return ( float ) Math. Sqrt ( x* x + y* y + z* z) ;
}
}
}
Vehicle vehicle_1;
vehicle_1 = new Vehicle ( ) ;
vehicle_1. speed = 10 ;
vehicle_1. Run ( ) ;
vehicle_1. Stop ( ) ;
vehicle_1. x = 20 ;
vehicle_1. y = 30 ;
vehicle_1. z = 40 ;
Console. Write ( vehicle_1. Length ( ) ) ;
Console. ReadKey ( ) ;