A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 一扇车门 中级黑马   /  2013-4-25 13:41  /  1273 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

为什么a的值赋给不了picPhoto.height??
picphoto.height初始值是20
int a = Convert.ToInt32(picphoto.Height * 1.1);//执行后a=22
picphoto.Height = a; //而这里a虽然是22,picphoto仍然是20
更多图片 小图 大图
组图打开中,请稍候......

1 个回复

倒序浏览
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;

  5. namespace Test2
  6. {
  7.     public class Photo
  8.     {
  9.         public int height;
  10.         public int width;
  11. //定义一个有两个参数并带有默认值的构造方法
  12.         public Photo(int height = 20,int width = 0)
  13.         {
  14.             this.height = height;
  15.             this.width = width;
  16.         }
  17. //定义一个用于输出对象数据成员的值得方法
  18.         public void show()
  19.         {
  20.             System.Console.WriteLine("对象的高为{0},\n对象的宽为{1}", this.height, this.width);
  21.             System.Console.ReadLine();

  22.         }
  23.     }
  24.     class Program
  25.     {
  26.         static void Main(string[] args)
  27.         {
  28.             
  29.             Photo picPhoto = new Photo();//创建一个Photo类的实例picPhoto
  30.             int a = Convert.ToInt32(picPhoto.height * 1.1);
  31.             System.Console.WriteLine("a的值是{0}",a);
  32.             picPhoto.height = a;
  33.             picPhoto.show();
  34.         }
  35.     }
  36. }
复制代码
自己运行一下代码看看结果
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马