- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Test2
- {
- public class Photo
- {
- public int height;
- public int width;
- //定义一个有两个参数并带有默认值的构造方法
- public Photo(int height = 20,int width = 0)
- {
- this.height = height;
- this.width = width;
- }
- //定义一个用于输出对象数据成员的值得方法
- public void show()
- {
- System.Console.WriteLine("对象的高为{0},\n对象的宽为{1}", this.height, this.width);
- System.Console.ReadLine();
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
-
- Photo picPhoto = new Photo();//创建一个Photo类的实例picPhoto
- int a = Convert.ToInt32(picPhoto.height * 1.1);
- System.Console.WriteLine("a的值是{0}",a);
- picPhoto.height = a;
- picPhoto.show();
- }
- }
- }
复制代码 自己运行一下代码看看结果 |