using System;
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
Myclass myclass = new Myclass();
myclass.Myint = 1;
Console.WriteLine(myclass.Myint);
myclass.Myint = -1;
Console.WriteLine(myclass.Myint);
Console.ReadLine();
}
}
class Myclass
{
int myint;
public int Myint
{
get
{
return myint;
}
set
{
if (value > 0)
{
myint = value;
}
else
{
Console.WriteLine("myint字段只接受大于0的值!");
}
}
}
}
}-------------------------------------------------------------------------------------
输出是:
1
myint字段只接受大于0的值!
1
------------------------------------------------------------------------------------1
myint字段只接受大于0的值!
这两个输出好理解 最后一个输出1 怎么解释?从哪里来的?
using System.Collections.Generic;
using System.Text;namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
Myclass myclass = new Myclass();
myclass.Myint = 1;
Console.WriteLine(myclass.Myint);
myclass.Myint = -1;
Console.WriteLine(myclass.Myint);
Console.ReadLine();
}
}
class Myclass
{
int myint;
public int Myint
{
get
{
return myint;
}
set
{
if (value > 0)
{
myint = value;
}
else
{
Console.WriteLine("myint字段只接受大于0的值!");
}
}
}
}
}-------------------------------------------------------------------------------------
输出是:
1
myint字段只接受大于0的值!
1
------------------------------------------------------------------------------------1
myint字段只接受大于0的值!
这两个输出好理解 最后一个输出1 怎么解释?从哪里来的?
解决方案 »
- SQL存储过程行转列 有空值怎么处理
- 如何在点击按钮后重启C#做的应用程序?
- TabPage加一个pictureBox,然后,想在这个pictureBox上绘制图形,图形根据另外一个控件选择。怎么加?
- C#里如何修改图片(以路径形式读取的图片)的长宽(大小)?
- 求.NET大文件上传程序
- 诚招DotNet系统分析员
- C#调用infoplus21_api.dll问题
- dataGridView中怎么用代码方式把选中行,定位到指定行
- 点击按钮弹出剧中遮罩层????(点击后不显示)在线等~~~~~
- 请问,那有whitehorse下载?
- dotnettextbox发布之后不能用
- 全球化,太不爽,资源包,没地放,调不到,吃不着,各位朋友来帮忙啊来帮忙!
{
int myint;
public int Myint
{
get
{
return myint;
}
set
{
if (value > 0)
{
myint = value;
}
else
{
myint = 999999999;
Console.WriteLine("myint字段只接受大于0的值!");
}
}
}
}
{
static void Main(string[] args)
{
Myclass myclass = new Myclass();
myclass.Myint = 1;
Console.WriteLine(myclass.Myint); 1
myclass.Myint = -1;
Console.WriteLine(myclass.Myint); 3
Console.ReadLine();
}
}
class Myclass
{
int myint;
public int Myint
{
get
{
return myint;
}
set
{
if (value > 0)
{
myint = value;
}
else
{
Console.WriteLine("myint字段只接受大于0的值!"); 2
}
并没有改变。。你重新输出了一次