摘要: C#的两大数据类型分别值类型和引用类型。很多人或许闭着眼睛都能说出值类型包括简单类型、结构体类型和枚举类型,引用类型包括自定义类、数组、接口、委托等,但是当被问及两者之间的联系和区别,什么时候用struct什么时候用class时,就常常混淆不消了。为此,了解值类型和引用类型的本质差异就变的很有必要了。1.值类型直接存储其值,变量本身就包含了其实例数据,而引用类型保存的只是实例数据的内存引用。因此,一个值类型变量就永远不会影响到其他的值类型变量,而两个引用类型变量则很有可能指向同一地址,从而发生相互影响。2.从内存分配上来看,值类型通常分配在线程的堆栈上,作用域结束时,所占空间自行释放,效率高, 阅读全文
posted @ 2012-07-13 01:22 Fan帥帥 阅读(270) 评论(0) 推荐(0) 编辑
摘要: 简单实现: 1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 using System.Data.SqlClient;10 using System.Text.RegularExpressions;11 12 namespace 用户登录13 { 阅读全文
posted @ 2012-07-13 01:09 Fan帥帥 阅读(217) 评论(0) 推荐(0) 编辑
摘要: 1、建立连接数据库 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Data; 6 using System.Data.SqlClient; 7 8 9 namespace 连接数据库10 {11 class Program12 {13 static void Main(string[] args)14 { //要连接数据库就要一个连接字符串,连接数据库的实例名,数据库... 阅读全文
posted @ 2012-07-13 01:00 Fan帥帥 阅读(237) 评论(0) 推荐(0) 编辑
摘要: 1、文件的复制static void Main(string[] args) { FileStream filer = new FileStream(@"dotnet基础加强练习.txt", FileMode.Open, FileAccess.Read); FileStream filew = new FileStream(@"2.txt", FileMode.Create, FileAccess.Write); byte[] by =new byte[100]; int count = 0; using... 阅读全文
posted @ 2012-07-13 00:55 Fan帥帥 阅读(196) 评论(0) 推荐(0) 编辑
摘要: 1、走马灯static void Main(string[] args){ string str = "我是一个走马灯"; while (true) { Console.Clear(); string head = str[0].ToString(); string body = str.Substring(1); str = body + head; Console.WriteL... 阅读全文
posted @ 2012-07-13 00:27 Fan帥帥 阅读(219) 评论(0) 推荐(0) 编辑
摘要: 真假Dcuknamespace Duck{ abstract class SubDuck { public abstract string Name { get; set; } //string name; //public string Name //{ // get { return name; } // set { name = value; } //} public void Sw... 阅读全文
posted @ 2012-07-13 00:20 Fan帥帥 阅读(206) 评论(0) 推荐(0) 编辑
摘要: // 练习:// 写一个Person和Student,姓名(name)性别(gender)年龄(age)由父类构造方法初始化// 年龄默认为0,性别随机,姓名有子类指定调用// 创建一个Student对象,并做自我介绍// 同时实现:实例化一个Student对象,指定姓名,性别,年龄namespace 继承_封装_多态{class Program{static void Main(string[] args){Student s1 = new Student("张三",12);s1.SayHello();Student s2 = new Student("小王&q 阅读全文
posted @ 2012-07-13 00:14 Fan帥帥 阅读(137) 评论(0) 推荐(0) 编辑
摘要: public Form1() { InitializeComponent(); // 默认情况下,窗体由操作系统分配位子 StartPosition = FormStartPosition.Manual; Location = new Point(0, 0); } int seed = 5; private void timer1_Tick(object sender, EventArgs e) { // 此时写在里... 阅读全文
posted @ 2012-07-13 00:11 Fan帥帥 阅读(167) 评论(0) 推荐(0) 编辑
摘要: 1、求min与max间数的所有奇数的和 static void Main(string[] args) { Console.WriteLine(res); Console.ReadKey(); } private static int Munodd(int min,int max) { int num = 0; for (int i = min; i <= max; i++) { if (i % 2 == 1) { num += i; } } return num; }2、找数组中... 阅读全文
posted @ 2012-07-13 00:09 Fan帥帥 阅读(176) 评论(0) 推荐(0) 编辑