[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SufeiClass
{
class Sufei
{
//变量成员
public string name;
public int age;
public int Age
{
get
{
return age;
}
set
{
if (value <= 0)
age = 0;
else
age = value;
}
}
private int count = 0; //用来记录积分
//函数成员
//函数:登陆
private void Hello()
{
Console.Write("嗨,我是{0},我今年{1}岁了。", name,age);
}
//函数:写文章
public void WriteAticle()
{
Hello();
Console.WriteLine("你的帖子已经被录入精华,谢谢发言");
}
//函数:奖励积分
public void JiangLi()
{
count++;
Hello();
Console.WriteLine("我已经积攒{0}积分!", count);
}
}
}
[C#] 纯文本查看 复制代码
class Program
{
static void Main(string[] args)
{
//申明对象wwwconsumer
Sufei wwwconsumer = new Sufei();
//访问数据成员
wwwconsumer.age = 40;
wwwconsumer.name = "wwwconsumer";
Console.WriteLine("嗨,我是{0},我今年{1}岁了。", wwwconsumer.name, wwwconsumer.age);
//调用函数成员
wwwconsumer.WriteAticle();
wwwconsumer.JiangLi();
wwwconsumer.JiangLi();
}
}
}