MySQL是一个非常流行的小型关系型数据库管理系统,2008年1月16号被Sun公司收购。目前MySQL被广泛地应用在Internet上的中小型网站中。由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL作为网站数据库。

1、phpMyAdmin(http://www.phpmyadmin.net/)

 

phpMyAdmin

 

phpMyAdmin是最常用的MySQL维护工具,是一个用PHP开发的基于Web方式架构在网站主机上的MySQL管理工具,支持中文,管理数据库非常方便。不足之处在于对大数据库的备份和恢复不方便。

2、MySQLDumper(http://www.mysqldumper.de/en/)

 

MySQLDumper

 

MySQLDumper使用PHP开发的MySQL数据库备份恢复程序,解决了使用PHP进行大数据库备份和恢复的问题,数百兆的数据库都可以方便的备份恢复,不用担心网速太慢导致中间中断的问题,非常方便易用。这个软件是德国人开发的,还没有中文语言包。

3、Navicat(http://www.navicat.com/)

 

Navicat

 

Navicat是一个桌面版MySQL数据库管理和开发工具。和微软SQLServer的管理器很像,易学易用。Navicat使用图形化的用户界面,可以让用户使用和管理更为轻松。支持中文,有免费版本提供。

4、MySQL GUI Tools(http://dev.mysql.com/downloads/gui-tools/)

 

MySQL GUI Tools

 

MySQL GUI Tools是MySQL官方提供的图形化管理工具,功能很强大,值得推荐,可惜的是没有中文界面。

5、MySQL ODBC Connector(http://dev.mysql.com/downloads/connector/odbc/)

 

MySQL ODBC Connector

 

MySQL官方提供的ODBC接口程序,系统安装了这个程序之后,就可以通过ODBC来访问MySQL,这样就可以实现SQLServer、Access和MySQL之间的数据转换,还可以支持ASP访问MySQL数据库。

以上就是我介绍的五个常用的MySQL维护管理工具,如果你知道更好的MySQL工具,请留言和我们分享。

(作者博客:www.williamlong.info

posted @ 2011-12-13 20:36 青春煞人 阅读(50) 评论(0) 编辑

mysql 下载地址

下面的是MySQL安装的图解,用的可执行文件安装的,详细说明了一下!打开下载的mysql安装文件mysql-5.0.27-win32.zip,双击解压缩,运行“setup.exe”,出现如下界面

mysql安装图文教程1
mysql安装图文教程1
mysql安装向导启动,按“Next”继续
mysql图文安装教程2
mysql图文安装教程2
选择安装类型,有“Typical(默认)”、“Complete(完全)”、“Custom(用户自定义)”三个选项,我们选择“Custom”,有更多的选项,也方便熟悉安装过程:
mysql图文安装教程3
mysql图文安装教程3
在“Developer Components(开发者部分)”上左键单击,选择“This feature, and all subfeatures, will be installed on local hard drive.”,即“此部分,及下属子部分内容,全部安装在本地硬盘上”。在上面的“MySQL Server(mysql服务器)”、“Client Programs(mysql客户端程序)”、“Documentation(文档)”也如此操作,以保证安装所有文件。点选“Change...”,手动指定安装目录。
mysql图文安装教程4
mysql图文安装教程4
填上安装目录,我的是“F:\Server\MySQL\MySQL Server 5.0”,也建议不要放在与操作系统同一分区,这样可以防止系统备份还原的时候,数据被清空。按“OK”继续。
mysql图文安装教程5
mysql图文安装教程5
返回刚才的界面,按“Next”继续
mysql图文安装教程6
mysql图文安装教程6
确认一下先前的设置,如果有误,按“Back”返回重做。按“Install”开始安装。
 
mysql图文安装教程7
mysql图文安装教程7
正在安装中,请稍候,直到出现下面的界面
 
mysql图文安装教程8
mysql图文安装教程8
这里是询问你是否要注册一个mysql.com的账号,或是使用已有的账号登陆mysql.com,一般不需要了,点选“Skip Sign-Up”,按“Next”略过此步骤。
 
mysql图文安装教程9
mysql图文安装教程9
现在软件安装完成了,出现上面的界面,这里有一个很好的功能,mysql配置向导,不用向以前一样,自己手动乱七八糟的配置my.ini了,将 “Configure the Mysql Server now”前面的勾打上,点“Finish”结束软件的安装并启动mysql配置向导。
 
mysql图文安装教程10
mysql图文安装教程10
mysql配置向导启动界面,按“Next”继续
mysql图文安装教程10
mysql图文安装教程10
选择配置方式,“Detailed Configuration(手动精确配置)”、“Standard Configuration(标准配置)”,我们选择“Detailed Configuration”,方便熟悉配置过程。
mysql图文安装教程11
mysql图文安装教程11
选择服务器类型,“Developer Machine(开发测试类,mysql占用很少资源)”、“Server Machine(服务器类型,mysql占用较多资源)”、“Dedicated MySQL Server Machine(专门的数据库服务器,mysql占用所有可用资源)”,大家根据自己的类型选择了,一般选“Server Machine”,不会太少,也不会占满。
mysql图文安装教程12
mysql图文安装教程12
选择mysql数据库的大致用途,“Multifunctional Database(通用多功能型,好)”、“Transactional Database Only(服务器类型,专注于事务处理,一般)”、“Non-Transactional Database Only(非事务处理型,较简单,主要做一些监控、记数用,对MyISAM数据类型的支持仅限于non-transactional),随自己的用途而选择了,我这里选择“Transactional Database Only”,按“Next”继续。
 
mysql图文安装教程13
mysql图文安装教程13
对InnoDB Tablespace进行配置,就是为InnoDB 数据库文件选择一个存储空间,如果修改了,要记住位置,重装的时候要选择一样的地方,否则可能会造成数据库损坏,当然,对数据库做个备份就没问题了,这里不详述。我这里没有修改,使用用默认位置,直接按“Next”继续
 
mysql图文安装教程14
mysql图文安装教程14
选择您的网站的一般mysql访问量,同时连接的数目,“Decision Support(DSS)/OLAP(20个左右)”、“Online Transaction Processing(OLTP)(500个左右)”、“Manual Setting(手动设置,自己输一个数)”,我这里选“Online Transaction Processing(OLTP)”,自己的服务器,应该够用了,按“Next”继续
mysql图文安装教程15
mysql图文安装教程15
是否启用TCP/IP连接,设定端口,如果不启用,就只能在自己的机器上访问mysql数据库了,我这里启用,把前面的勾打上,Port Number:3306,在这个页面上,您还可以选择“启用标准模式”(Enable Strict Mode),这样MySQL就不会允许细小的语法错误。如果您还是个新手,我建议您取消标准模式以减少麻烦。但熟悉MySQL以后,尽量使用标准模式,因为它可以降低有害数据进入数据库的可能性。按“Next”继续
 
mysql图文安装教程16
mysql图文安装教程16
西文编码,第二个是多字节的通用utf8编码,都不是我们通用的编码,这里选择第三个,然后在Character Set那里选择或填入“gbk”,当然也可以用“gb2312”,区别就是gbk的字库容量大,包括了gb2312的所有汉字,并且加上了繁体字、和其它乱七八糟的字——使用mysql的时候,在执行数据操作命令之前运行一次“SET NAMES GBK;”(运行一次就行了,GBK可以替换为其它值,视这里的设置而定),就可以正常的使用汉字(或其它文字)了,否则不能正常显示汉字。按 “Next”继续。
mysql图文安装教程17
mysql图文安装教程17
选择是否将mysql安装为windows服务,还可以指定Service Name(服务标识名称),是否将mysql的bin目录加入到Windows PATH(加入后,就可以直接使用bin下的文件,而不用指出目录名,比如连接,“mysql.exe -uusername -ppassword;”就可以了,不用指出mysql.exe的完整地址,很方便),我这里全部打上了勾,Service Name不变。按“Next”继续。选择是否将mysql安装为windows服务,还可以指定Service Name(服务标识名称),是否将mysql的bin目录加入到Windows PATH(加入后,就可以直接使用bin下的文件,而不用指出目录名,比如连接,“mysql.exe -uusername -ppassword;”就可以了,不用指出mysql.exe的完整地址,很方便),我这里全部打上了勾,Service Name不变。按“Next”继续。
 
mysql图文安装教程18
mysql图文安装教程18
这一步询问是否要修改默认root用户(超级管理)的密码(默认为空),“New root password”如果要修改,就在此填入新密码(如果是重装,并且之前已经设置了密码,在这里更改密码可能会出错,请留空,并将“Modify Security Settings”前面的勾去掉,安装配置完成后另行修改密码),“Confirm(再输一遍)”内再填一次,防止输错。 “Enable root access from remote machines(是否允许root用户在其它的机器上登陆,如果要安全,就不要勾上,如果要方便,就勾上它)”。最后“Create An Anonymous Account(新建一个匿名用户,匿名用户可以连接数据库,不能操作数据,包括查询)”,一般就不用勾了,设置完毕,按“Next”继续。
 
mysql图文安装教程19
mysql图文安装教程19
确认设置无误,如果有误,按“Back”返回检查。按“Execute”使设置生效。
 
mysql图文安装教程20
mysql图文安装教程20
设置完毕,按“Finish”结束mysql的安装与配置——这里有一个比较常见的错误,就是不能“Start service”,一般出现在以前有安装mysql的服务器上,解决的办法,先保证以前安装的mysql服务器彻底卸载掉了;不行的话,检查是否按上面一步所说,之前的密码是否有修改,照上面的操作;如果依然不行,将mysql安装目录下的data文件夹备份,然后删除,在安装完成后,将安装生成的 data文件夹删除,备份的data文件夹移回来,再重启mysql服务就可以了,这种情况下,可能需要将数据库检查一下,然后修复一次,防止数据出错
转自:jb51.net
posted @ 2011-12-12 10:52 青春煞人 阅读(90) 评论(0) 编辑

I have developed a Windows Application in Visual Studio 2008 some years ago and now it has been updated in Visual Studio 2010.

The application connects to a MySQL database and after porting it to VS2010, the IDE does not show the connection to the MySQL in Server Explorer. Also when trying to add the data connection, in the Choose Data Source window it does not show the MySQL Database.The MySQL connector (an older version –  5.2.7.0) was installed and the reference to MySql.Data namespace was added. There were no problems compiling the project, just VS2010 could not see the connector when trying to create a new Data connection.

This is a compatibility problem between VS2010 and MySQL connector. The same problem has been reported also for the MySql Connector/Net 6.2.2.

The problem seems that has been solved with the release of the MySql Connector/Net 6.3.4. But this version has another problem.The MySQL connector does not work on Windows XP, only on Windows 7. In my case I could not install the connector (the installation wizard failed). So solving this problem you could not install the application on Windows XP because it will not find the required connector. This problem has another solution: How to deploy .NET applications that use modules with different version than the development ones

So, in order to connect to a MySql database from VS2010 you need to

  • download the latest version of the MySql Connector/NET fromhttp://www.mysql.com/downloads/connector/net/
  • install the connector (if you have an older version you need to remove it from Control Panel -> Add / Remove Programs)
  • open Visual Studio 2010
  • open Server Explorer Window (View -> Server Explorer)
Visual Studio 2010 - Server Explorer window

Visual Studio 2010 - Server Explorer window

  • use Connect to Database button
  • in the Choose Data Source windows select MySql Database and press Continue
VS2010 - MySQL DataSource

VS2010 - MySQL DataSource

  • in the Add Connection window
    • set server name: 127.0.0.1 or localhost for MySql server running on local machine or an IP address for a remote server
    • username and password
    • if the the above data is correct and the connection can be made, you have the possibility to select the database
VS2010 MySQL Connection properties

VS2010 MySQL Connection properties

If you want to connect to a MySql database from a C# application (Windows or Web) you can use the next sequence:

//define the connection reference and initialize it
MySql.Data.MySqlClient.MySqlConnection msqlConnection = null;
msqlConnection = new MySql.Data.MySqlClient.MySqlConnection(“server=localhost;user id=UserName;Password=UserPassword;database=DatabaseName;persist security info=False”);
//define the command reference
MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();
//define the connection used by the command object
msqlCommand.Connection = this.msqlConnection;
//define the command text
msqlCommand.CommandText = "SELECT * FROM TestTable;";
try
{
//open the connection
this.msqlConnection.Open();
//use a DataReader to process each record
MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader();
while (msqlReader.Read())
{
//do something with each record
}
}
catch (Exception er)
{
//do something with the exception
}
finally
{
//always close the connection
this.msqlConnection.Close();
}

转自:http://www.itcsolutions.eu

posted @ 2011-12-12 10:16 青春煞人 阅读(74) 评论(0) 编辑

1.Replace(替换字符):
public string Replace(char oldChar,char newChar);在对象中寻找oldChar,如果寻找到,就用newChar将oldChar替换掉。
如:
string st = "abcdef";
string newstring = st.Replace(“a“, “x“);
Console.WriteLine(newstring); //即:xbcdef

public string Replace(string oldString,string newString);在对象中寻找oldString,如果寻找到,就用newString将oldString替换掉。
如:
string st = "abcdef";
string newstring = st.Replace("abc", "xyz");
Console.WriteLine(newstring); //即:xyzdef


2.Remove(删除字符):
public string Remove(int startIndex);从startIndex位置开始,删除此位置后所有的字符(包括当前位置所指定的字符)。
如:
string st = "abcdef";
string newstring = st.Remove(4);
Console.WriteLine(newstring); //即:abcd

public string Remove(int startIndex,int count);从startIndex位置开始,删除count个字符。
如:
string st = "abcdef";
string newstring = st.Remove(4,1);
Console.WriteLine(newstring); //即:abcdf


3.Substring(字符串提取):
public string Substring(int startIndex);从startIndex位置开始,提取此位置后所有的字符(包括当前位置所指定的字符)。
如:
string st = "abcdef";
string newstring = st.Substring(2);
Console.WriteLine(newstring); //即:cdef

public string Substring(int startIndex,int count);从startIndex位置开始,提取count个字符。
如:
string st = "abcdef";
string newstring = st.Substring(2,2);
Console.WriteLine(newstring); //即:cd

4.Trim(清空空格):
public string Trim ():将字符串对象包含的字符串两边的空格去掉后返回。
public string Trim ( params char[] trimChars ):从此实例的开始和末尾移除数组中指定的一组字符的所有匹配项。
如:
string st ="abcdef";
string newstring = st.Trim(new char[] {“a“});//寻找st字符串中开始与末尾是否有与“a“匹配,如有,将其移除。
Console.WriteLine(newstring); //即:bcdef
注:如果字符串为"aaaabcdef",返回依然为bcdef。当移除第一个a时,开始依然为a,继续移除,直到没有。
public string TrimEnd ( params char[] trimChars ):对此实例末尾与指定字符进行匹配,true则移除
public string TrimStart ( params char[] trimChars ):对此实例开始与指定字符进行匹配,true则移除

5.ToLower(转换大小写)

public string ToLower():将字符串对象包含的字符串中的大写全部转换为小写。

6.IndexOf(获取指定的字符串的开始索引)
public int IndexOf (sring field):在此实例中寻找field,如果寻找到,返回开始索引,反之,返回-1。
如:
string st = "abcdef";
int num=st.IndexOf("bcd");
Console.WriteLine(num); //即:1

7.Equals(是否相等)
public bool Equals (string value):比较调用方法的字符串对象包含字符串和参数给出的对象是否相同,如相同,就返回true,反之,返回false。
如: string a = "abcdef";
bool b = a.Equals("bcdef");
Console.WriteLine(b);//即:false

public bool Equals ( string value, StringComparison comparisonType ):比较调用方法的字符串对象包含字符串和参数给出的对象是否在不区分大小写的情况下相同,如相同,就返回true,反之,返回false,第二个参数将指定区域性、大小写以及比较所用的排序规则.
如:
string a = "ABCDEF";
bool b = a.Equals("abcdef",StringComparison.CurrentCultureIgnoreCase);
Console.WriteLine(b);//即:true


8.Split(拆分)
public string[] Split ( params char[] separator ):根据separator 指定的没有字符分隔此实例中子字符串成为Unicode字符数组, separator可以是不包含分隔符的空数组或空引用。
public string[] Split ( char[] separator, int count ):参数count 指定要返回的子字符串的最大数量。
如:
string st = "语文|数学|英语|物理";
string[] split = st.Split(new char[]{“|“},2);
for (int i = 0; i < split.Length; i++)
{
Console.WriteLine(split[i]);
}
注:count不填则全部拆分

public enum StringSplitOptions
成员名称 说明
None 返回值包括含有空字符串的数组元素
RemoveEmptyEntries 返回值不包括含有空字符串的数组元素

如:
string st = "语文|数学||英语|物理";
string[] split = st.Split(new char[]{“|“},StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < split.Length; i++)
{
Console.WriteLine(split[i]);
}
将StringSplitOptions枚举和Split()方法联系起来:
1. public string[] Split ( char[] separator, StringSplitOptions options ):options指定StringSplitOptions枚举的RemoveEmptyEntries以省略返回的数组中的空数组元素,或指定StringSplitOptions枚举的None以包含返回的数组中的空数组元
2. public string[] Split ( char[] separator, int count, StringSplitOptions options )
3. public string[] Split ( string[] separator, StringSplitOptions options )
4. public string[] Split ( string[] separator, int count, StringSplitOptions options )


9.Contains(判断是否存在)
public bool Contains(string text):如果字符串中出现text,则返回true,反之false,如果text为("")也返回true。
如:
string st="语文数学英语";
bool b=st.Contains("语文");
Console.WriteLine(b);//true


10.EndsWith,StartsWith(判断字符串的开始或结束)
public bool EndsWith ( string value ):判断对象包含字符串是否以value指定的字符串结束,是则为 true;否则为 false。
public bool EndsWith ( string value, StringComparison comparisonType ):第二个参数设置比较时区域、大小写和排序规则。
public bool StartsWith ( string value ):判断对象包含字符串是否以value指定的字符串开始,是则为 true;否则为 false。
public bool StartsWith ( string value, StringComparison comparisonType ) :第二个参数设置比较时区域、大小写和排序规则。
如:
string st="语文数学英语abc";
bool b=st.EndsWith("英语ABC",StringComparison.CurrentCultureIgnoreCase);//第二个参数忽略大小比较。
Console.WriteLine(b);//true

11.Insert(字符串插入)
public string Insert ( int startIndex, string value ):在指定的字符串下标为startIndex前插入字符串value。返回插入后的值。
如:
string st="语文数学英语abc";
string newst=st.Insert(6,"物理");//注:在指定索引“前”插入。
Console.WriteLine(newst);//即:语文数学英语物理abc

注:作者:岁月苍狼---相博仁    文章来源:hi.baidu.com   

posted @ 2011-08-21 12:45 青春煞人 阅读(203) 评论(0) 编辑

虚方法(virtual)
virtual关键字用地修饰方法、属性、索引器或事件声明,并且允许在派生类中重写这些对象。
virtual表示此方法是一个虚方法,override表示要覆盖主线类的虚方法,对方法进行重写。
他们经常一起配合使用,这样就形成了多态。
多态(Polymorphism)
多态是指两个或多个属于不同类的对象,对同一个消息做出不同响应的能力。
多态概念的举例
●外科医生 cut
●发型师 cut
●演员  cut
当外科医生接收到cut指令时,外科医生会对病人进行手术
当发型师收到cut指令时,发型师会对顾客修剪头发
当演员收到cut指令时,演员会停止表演。

这个就是多态,对同一事件发出不同响应的能力。
使用举例

using System;
class Employee
{
	protected string _name;
	public Employee(){}
	public Employee(string name)
	{
		_name=name;
	}
	public virtual void StartWork()//rivtual常与overrider一起使用
	{
		Console.Write(_name+"开始工作");
	}
}
class Manager:Employee
{
	public Manager(string name):base(name){}
	//此构造函数调用了基类的构造函数,把string name的name传递到base(name)的构造函数里面
	//从而,Manager类里的构造函数会执行Employee中的构造函数
	public override void StartWork()
	{
		Console.WriteLine("给员工下达任务");
	}
	
}
class Secretary:Employee
{
	public Secretary(string name):base(name){}
	public override void StartWork()
	{
		Console.WriteLine("协助经理");
	}
}
class Test
{
	static void Main()
	{
		Employee[] emp=new Employee[3];
		emp[0]=new Manager("tom");
		emp[1]=new Secretary("lilly");
		emp[2]=new Secretary("mary");
		Console.WriteLine("we工作开始!");
		foreach(Employee e in emp)
		{
			e.StartWork();
		}
	}
}

此代码功能用多态实现有很多好处,例如这样会非常便于维护。我们程序里有员工、经理、秘书,如果再添加
一个成员业务员则只需新增一个关于业务员的类,此类继承至员工类,相关的工作事件可以用override重
载方法实现。

posted @ 2011-08-14 17:52 青春煞人 阅读(13) 评论(0) 编辑

一、声明数级时要在各个元素的类型后面加上一组方括号,例:

int[] intergers;

二、要初始化特定大小的数组,可以使用new关键字,在类型后面的方括号中给出大小。例:

int[] integers=new int[2];  

注意:在c语言中声明数组并分配内存空间只需int a[3]即可。而在c#中声明变量int[] integers;,分配内存空间new int[2];

此外,中括号的位置也于c语言不同。c语言中中括号在变量的后面,而c#中中括号在类型的后面。例:

c语言:int a[2];

c#:int[2] a;

三、也可以声明时不初始化,以后动态指定大小。例:

int[] integers;

integers=new int[32];

四、在初始化数组时,不能用变量设置数组应包含多少元素,但是可以给数组长度声明一个常。例:

const int len=3;

string[] s=new string[len];

五、要确定数组大小,可以用length来访问。例:

int arraylength=integers.Length;

Array.Sort(string)数组按正序排列

Array.Reverse逆序排列

六、多维数组

c#支持两数组。第一种是矩形数组。例:

string[,] strings;

第二种多维数组是正交数组

int[][] a=new int[3][];

a[0]=new int[4];

a[1]=new int[2];

a[2]=new int[1];

要声明一个正交三维数组应使用:

int[][][] array;

七、自定义类型数组的声明

public class userinfo
{
  string[] a=new string[3];
  string[][] b=new string[2][2];
  public void printA()
  {
    System.Console.WriteLine("this is array");
  }
} 

自定义数组声明:userinfo[] user=new userinfo[3];

posted @ 2011-08-14 09:42 青春煞人 阅读(32) 评论(0) 编辑

委托(delegate)


委托声明定义了一种类型,它用一组特定的参数以及返回类型来封闭方法。对于静态方法,委托对象
封装要调用的方法。对于实例方法,委托对象同时封闭一个实例和该实例上的一个方法。如果您有一
个委托对象和一组适当的参数,则可以用这些参数调用该委托。

委托提供了类似于c++中函数指针的功能,简单的说委托类型就是面向对象函数指针。
不过c++的函数指针只能指向静态的方法,而委托除了可以指向一个静态的函数方法外,还可以指
向对象的实例的方法。而最大的差异在于委托是完全的面向对象,且使用安全的类型,另外委托允许程序员在程序执行时传入
方法的名称,动态的决定预调用的方法。如此的弹性更能让程序员随心所欲的发挥。

委托的本质是一个类,任何可以声明类的地方都可以使用委托。

委托的使用举例

using System;
delegate void EatDelegate(string food);//委托的声明,返回值及形参要与所指向的函数对应
class MyDelegate
{
 static void zsEat(string food)
 {
  Console.WriteLine("zs eat "+food);
 }
 static void lsEat(string food)
 {
  Console.WriteLine("ls eat "+food);
 }
 static void wwEat(string food)
 {
  Console.WriteLine("ww eat "+food);
 }
 static void Main()
 {
  EatDelegate zs=new EatDelegate(zsEat);
  EatDelegate ls=new EatDelegate(lsEat);
  EatDelegate ww=new EatDelegate(wwEat);
  //方法一
  zs("apple");
  Console.WriteLine("--------------");
  //方法二
  EatDelegate eatChain;
  eatChain=zs+ls+ww;
  eatChain("orange");
  Console.WriteLine("--------------");
  //方法三
  eatChain-=zs;//??zs???
  eatChain("banana");
  Console.WriteLine("--------------");
  //方法四
  eatChain+=zs;//???zs???
  eatChain("banana");
  Console.WriteLine("--------------");
  //方法五,匿名方法
  /*
   * EatDelegate eatChain=null;
   * eatChain+=delegate(string food){console.writeLine("zs eat "+food);};
   * eatChain("pear");
   */
 }
}

posted @ 2011-08-13 16:36 青春煞人 阅读(23) 评论(0) 编辑
摘要: 索引器(indexer)索引器允许类或结构的实例按照与数组相同的方式进行索引。索引器类似于属性,不同之处在于它们的访问器采用参数。一、索引器与数组类的区别:数组类声明了多个实例,其内容存储在托管堆中,每个实例声明的名称都指向所对应的托管堆。索引器只需要声明一个实例,其内容存储在索引器的一个数组中。索引器的索引不只是int型,还可以是其它类型。using System.Collections;internal class ArrClass//没有索引器的类{ private readonly string name; public ArrClass(string name) { this.nam阅读全文
posted @ 2011-08-12 18:32 青春煞人 阅读(73) 评论(1) 编辑
摘要: 属性(property)属性是类、结构和接口的命名成员。它们提供了通过访问器(accessor)读、写或计算私有字段值的灵活机制。属性是这样的成员:它们提供灵活的机制来读取、编写或计算私有字段的值。可以像使用公共数据成员一样使用属性,但实际上它们是称为“访问器”的特殊方法。这使得数据在可被轻松访问的同时,仍能提供方法的安全性和灵活性。属性的命名规则及写作规范,例:internal class Property//一般类名要首字母大写。在声明类时,若class前未加修饰符则默认为internal{ static void Main() { Person p=new Person(); p.Nam阅读全文
posted @ 2011-08-12 10:10 青春煞人 阅读(21) 评论(0) 编辑
摘要: 类型的转换C#中类型转换(显隐)的机制分为两种:一、隐式转换(implicit conversions)二、显式转换(explict conversions)隐式转换不需要指明欲转变的类型;显式转换明确地使用转换运算符(cast)指定要转换成哪一种类型。C#允许程序员如果对于溢出进行处理 checked:检查是否出现溢出 unchecked:不检查是否出现溢出 例如:int a; long b=200000000000; try { a=checked((int)b); //也可使用checked语句,而非checked操作符 //checked //{ // (int)b; //这里可以对多阅读全文
posted @ 2011-08-10 12:21 青春煞人 阅读(167) 评论(0) 编辑