using System;
using System.Collections.Generic;
using System.Text;
using WebHelper;
//导入命名空间 using
//别名ALIAS的使用 using BT=TeamX.Bussiness;
//FXCl=Framework Class Library;
///Microsoft.VisualBasic vb6
///System core classes,types
///System.Collections Data structures
///System.Data DataBase
///System.Net NetWorking
///System.Windows.Forms GUI
///System.xml xml
///assembly 组件 NET的优势 没有DLL恶梦
/// 首先建立一个webhelper的类库
///将自己建立的类库导入 添加引用将WEBHELPER引入
///如何保护自己的只是产权:混淆代码
///学习程序要"戒急用忍"要做到不是重复的事情,人生不能做苦力。
namespace 面向对象__介绍
{
//名称空间的作用,管理不同的TEAM的名称相同的类的调用,减少类名冲突。
//增加可读性
public class TestMain {
public static void Main()
{
Authetic Aut;
Aut = new Authetic();
bool done;
done = Aut.ChangePassWord("zhukun","19831211");
if (done == true)
Console.WriteLine("password ok");
else
Console.WriteLine("not ok");
//else 如果不写大括号,那么只会默认执行else 后面的第一句代码。
Console.WriteLine("我的Authetic的密码长度为{0}", Authetic.GetMinPassWordLength());
Showme.ShowMe();
Console.ReadLine();//{0}
//iDisposeable接口
}
}
class Authetic
{
private string PassWord;//属性封装,外部类没有办法直接访问这个属性。
private string UserName;
private static uint ninstanceCreated=0;
private static uint MinPassWordLenth = 6;//静态不需要实例化的
//构造函数:没有返回类型。
//成员变量表示对象的特征
//析构函数不能重载
//类是C#是一种结构,用于模拟在现实生活中的对象。
public Authetic()
{
PassWord = "zhukun";
++ninstanceCreated;//统计类被初始化了多少次
}
public Authetic(string strUserName ,string strPassWord)//带参数的构造函数。
{
this.PassWord = strPassWord;
this.UserName = strUserName;
++ninstanceCreated;
}//如果你写了一个带参数的构造函数,那么一定要写一个不带参数的构造函数,这个要自己写。
static Authetic()
{
System.Console.WriteLine("the static constructor hai been invoked");
}//用于执行仅需执行一次的特定操作。在创建第一个实例或者任何静态成员之前,将自动调用构造函数。
//静态的构造函数会在执行的时候第一个被执行。
//从其他构造函数中调用构造函数
public Authetic(string strUserName)
: this()
{
}
//析构函数:用于执行清除操作的特殊方法。
~Authetic()
{
}
//判断密码是否正确
public bool IsPassWordCrrent(string userPassword)
{
return (PassWord == userPassword) ? true : false;
}
//修改密码
public bool ChangePassWord(string OldPassWord,string NewPassWord)
{
if (OldPassWord == PassWord)
{
PassWord = NewPassWord;
return true;
}
return false;
}
//布尔型的数据返回布尔的类型。经常用布尔去判断一个对象的属性是否修改。
public static uint GetMinPassWordLength()//静态的方法只能访问静态的成员变量
{
return MinPassWordLenth;
}
//如何设置静态的成员变量的值,为了实现这个,引入了属性这个概念。
//我们要设置多个对象,例如要设置密码的长度,就希望所有的密码的长度都是一样的,不希望每次
//都去制定一下密码的长度。一种解决办法是设置静态的密码长度。因为静态的数据在内存中只存在
//一个内存的地址。如何解决假如有N个变量,但是变量的实例化要求有不同的数值。
//如果是局部变量,使用前必须初始化,其他在编译的时候初始化。
}
}
浙公网安备 33010602011771号