public class Taxi
{
public bool isInitialized;
public Taxi()
{
isInitialized = true;
}
}
class TestTaxi
{
static void Main()
{
Taxi t = new Taxi();
Console.WriteLine(t.isInitialized);
}
}
class NLog
{
// Private Constructor:
private NLog() { }
public static double e = Math.E; //2.71828...
}
int i = new int(); Console.WriteLine(i);
int i; Console.WriteLine(i);
int a = 44; // Initialize the value type...
int b;
b = 33; // Or assign it before using it.
Console.WriteLine("{0}, {1}", a, b);
public class Employee
{
public int salary;
public Employee(int annualSalary)
{
salary = annualSalary;
}
public Employee(int weeklySalary, int numberOfWeeks)
{
salary = weeklySalary * numberOfWeeks;
}
}
Employee e1 = new Employee(30000); Employee e2 = new Employee(500, 52);
public class Manager : Employee
{
public Manager(int annualSalary)
: base(annualSalary)
{
//Add further instructions here.
}
}
public Manager(int initialdata)
{
//Add further instructions here.
}
public Manager(int initialdata)
: base()
{
//Add further instructions here.
}
public Employee(int weeklySalary, int numberOfWeeks)
: this(weeklySalary * numberOfWeeks)
{
}
public Employee(int annualSalary)
{
salary = annualSalary;
}
class CoOrds
{
public int x, y;
// constructor
public CoOrds()
{
x = 0;
y = 0;
}
}
// A constructor with two arguments:
public CoOrds(int x, int y)
{
this.x = x;
this.y = y;
}
CoOrds p1 = new CoOrds(); CoOrds p2 = new CoOrds(5, 3);
class Circle : Shape
{
public Circle(double radius)
: base(radius, 0)
{
}
}
class CoOrds
{
public int x, y;
// Default constructor:
public CoOrds()
{
x = 0;
y = 0;
}
// A constructor with two arguments:
public CoOrds(int x, int y)
{
this.x = x;
this.y = y;
}
// Override the ToString method:
public override string ToString()
{
return (String.Format("({0},{1})", x, y));
}
}
class MainClass
{
static void Main()
{
CoOrds p1 = new CoOrds();
CoOrds p2 = new CoOrds(5, 3);
// Display the results using the overriden ToString method:
Console.WriteLine("CoOrds #1 at {0}", p1);
Console.WriteLine("CoOrds #2 at {0}", p2);
Console.ReadKey();
}
}
CoOrds #1 at (0,0) CoOrds #2 at (5,3)
public class Person
{
public int age;
public string name;
}
class TestPerson
{
static void Main()
{
Person person = new Person();
Console.WriteLine("Name: {0}, Age: {1}", person.name, person.age);
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
Name: , Age: 0
abstract class Shape
{
public const double pi = Math.PI;
protected double x, y;
public Shape(double x, double y)
{
this.x = x;
this.y = y;
}
public abstract double Area();
}
class Circle : Shape
{
public Circle(double radius)
: base(radius, 0)
{
}
public override double Area()
{
return pi * x * x;
}
}
class Cylinder : Circle
{
public Cylinder(double radius, double height)
: base(radius)
{
y = height;
}
public override double Area()
{
return (2 * base.Area()) + (2 * pi * x * y);
}
}
class TestShapes
{
static void Main()
{
double radius = 2.5;
double height = 3.0;
Circle ring = new Circle(radius);
Cylinder tube = new Cylinder(radius, height);
Console.WriteLine("Area of the circle = {0:F2}", ring.Area());
Console.WriteLine("Area of the cylinder = {0:F2}", tube.Area());
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
Area of the circle = 19.63 Area of the cylinder = 86.39
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有