• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
一蓑烟雨
C/C++,Linux,语音技术
博客园    首页    新随笔    联系   管理    订阅  订阅

随笔分类 -  C#学习

C#,wp7
base与this

摘要:1、base 关键字用于从派生类中访问基类的成员: (1) 调用基类上已被其他方法重写的方法,如base实例1; (2) 指定创建派生类实例时应调用的基类构造函数,如base实例2。 基类访问只能在构造函数、实例方法或实例属性访问器中进行。base实例1 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace BaseTest1 7 { 8 class Animal 9 {10 public v... 阅读全文
posted @ 2011-12-21 10:14 lovemu 阅读(263) 评论(0) 推荐(0)
定义类

摘要:1、类定义中可以使用的访问修饰符的组合 无或internal 类只能在当前项目中访问 public 类可以在任何地方访问 abstract 或 internalabstract 类只能在当前项目中访问,不能实例化,只能继承 public abstract 类可以任何地方访问,不能实例化,只能继承 sealed 或 internal sealed 类只能在当前项目中访问,不能派生,只能实例化 public sealed 类可以任何地方访问,不能派生,只能实例化2、要使接口可以公开访问,必须使用public interface abstract 和sealed不能在接... 阅读全文
posted @ 2011-12-12 16:15 lovemu 阅读(390) 评论(0) 推荐(0)
OOP之类、继承与重载

摘要:继承是派生类(子类)去实现,例如:public class MeiDiCooker:Cooker;重写使用override来重写基类(父类)的方法或属性;子类中重载父类中的方法时,父类相应的方法需要用virtual声明;重载使用new,重载则是对方法参数的个数、位置、参数类型进行了改变,这个前面说过;重写只是对方法里面的功能实现重新做的了编写,并没有对方法的参数进行添加、改变、删除。 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespa. 阅读全文
posted @ 2011-12-09 17:19 lovemu 阅读(1051) 评论(0) 推荐(0)
OOP之类与接口的区别

摘要:接口:只声明不定义;类:可以声明又定义;一个类可以实现多个接口;一个类只能继承一个类。打个比方:接口比作是一个插线板,可以被多个家用电器使用,但是一定要满足该插线板的条件才能正常使用,而类呢?就是造插线板的工厂,可以制造不同的标准的插线板,这个形象吧,呵呵!利用类和接口写的一个电饭煲预约煮饭的例子: 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace InterfaceClass 7 { 8 public interfac... 阅读全文
posted @ 2011-12-09 15:07 lovemu 阅读(1072) 评论(0) 推荐(0)
委托(delegate)

摘要:1、先看一个委托的例子 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace DeleGate 7 { 8 public delegate void GreetingDelegate(string name);//委托 9 10 class Program11 {12 private static void EnglishGreeting(string name)13 {14 ... 阅读全文
posted @ 2011-12-07 17:00 lovemu 阅读(246) 评论(0) 推荐(0)
结构与重载

摘要:1、结构跟C中类似,优点:集中处理常见任务,简化过程; 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace StructTest 7 { 8 struct huanghuang 9 { 10 public string firstName,lastName;11 public string wholeName()12 { 13 return f... 阅读全文
posted @ 2011-12-07 11:55 lovemu 阅读(197) 评论(0) 推荐(0)
变量的作用域

摘要:1、C#的变量仅能从代码的本地作用域访问,访问该变量要通过这个作用域来实现写个例子:(1)访问不了的情况 error 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace bianliang 7 { 8 class Program 9 {10 11 static void display()12 {13 Console.WriteLine("result:{0... 阅读全文
posted @ 2011-12-07 11:00 lovemu 阅读(207) 评论(0) 推荐(0)
ref和out

摘要:1、引用类型(ref、out)与值类型引用类型都是引用传递(两者都是按地址传递的),就是对传递进去的变量的修改会反映在原来的变量上;值类型当不用 out或者 ref的时候就是值传递,就是对传递进去的变量的修改不会反映在原来的变量上,修改的只是原来变量的一个副本。2、重载ref 和 out 关键字在运行时的处理方式不同,但在编译时的处理方式相同。因此,如果一个方法采用 ref 参数,而另一个方法采用 out 参数,则无法重载这两个方法;如果一个方法采用 ref 或 out 参数,而另一个方法不采用这两类参数,则可以进行重载。3、初始化ref 先初始化;out 在方法里初始化。4、ref 有进有出 阅读全文
posted @ 2011-12-05 10:30 lovemu 阅读(298) 评论(0) 推荐(0)
C#:从字符串反转看字符串处理

摘要:题目:接收用户输入的一个字符串,将其中的字符以与输入相反的顺序输出。方法一: 不可直接输出字符串,需要遍历输出 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace StrTest 7 { 8 class Program 9 {10 static void Main(string[] args)11 {12 string user = Console.ReadL... 阅读全文
posted @ 2011-12-01 09:42 lovemu 阅读(7404) 评论(7) 推荐(1)
C/C++与C#区别(5)

摘要:二维数组定义C/C++:int a[][]= {{1,1,3,2},{5,9,0,2},{3,4,7,5}}; int **a= {{1,1,3,2},{5,9,0,2},{3,4,7,5}};C#:二维固定矩阵 int[,] a={{1,1,3,2},{5,9,0,2},{3,4,7,5}}; 参差矩阵定义(二维可变数组):int[][] a=new int[3][];(1)C#下二维数组应用 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 ... 阅读全文
posted @ 2011-11-30 16:54 lovemu 阅读(291) 评论(0) 推荐(0)
foreach和for

摘要:1、foreach循环与for循环输出结果比较,能达到一样的输出效果。 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace ForeachApplication 7 { 8 class Program 9 {10 static void Main(string[] args)11 {12 int[] a = { 1,5,9,20,16};13 ... 阅读全文
posted @ 2011-11-30 12:00 lovemu 阅读(289) 评论(0) 推荐(0)
C/C++与C#区别(4)

摘要:1、数组定义 C/C++: int a[]; C#: int[] a;2、初始化数组 C/C++: int a[] = new int[5]{1,4,2,10,7}; C# : int[] a = new int[5]{1,4,2,10,7};3、一个小程序Program.cs 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace array 7 { 8 class Program 9 {10 ... 阅读全文
posted @ 2011-11-28 10:49 lovemu 阅读(230) 评论(0) 推荐(0)
枚举与结构体

摘要:1、结构体和枚举一样,都是在代码的主体外部声明的。 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace StructEnum 7 { 8 enum orientation : byte 9 { 10 north = 1,11 south = 2,12 east = 3,13 west = 414 }15 struct route16 ... 阅读全文
posted @ 2011-11-28 10:26 lovemu 阅读(2881) 评论(0) 推荐(0)
C/C++与C#区别(3)

摘要:C#:switch语句中运行完case后,必须要有break。 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace SwitchTest 7 { 8 class Program 9 {10 static void Main(string[] args)11 {12 int v = 2;13 switch (v)14 ... 阅读全文
posted @ 2011-11-22 17:32 lovemu 阅读(252) 评论(0) 推荐(0)
C/C++与C#区别(2)

摘要:C#:if判断语句中必须为布尔值,否则编译不通过1 int v1=10,v2=7;2 if(v1>v2)3 {4 Console.WriteLine("v1>v2");5 }6 else7 {8 Console.WriteLine("v1<v2");9 }C/C++比较灵活,无此限制 阅读全文
posted @ 2011-11-22 08:58 lovemu 阅读(219) 评论(0) 推荐(0)
C/C++与C#区别(1)

摘要:C需要在输出语句中指明数据类型1 int num;2 printf("num is %d\n",num);C++不需要在输出语句中指明数据类型1 int num;2 cout<<"num is "<<num<<endl;C# 不需要在输出语句中指明数据类型1 int num;2 Console.Write("num is {0}",num);3 Console.WriteLine(); 阅读全文
posted @ 2011-11-21 08:52 lovemu 阅读(212) 评论(0) 推荐(0)
new和override区别

摘要:1.编写个小程序,就可以理解new和override区别 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace Newoverride 7 { 8 class Dad 9 {10 public Dad()11 {12 Console.WriteLine("Dad construtor");13 }14 public virtual... 阅读全文
posted @ 2011-11-18 10:47 lovemu 阅读(1223) 评论(0) 推荐(1)
get和set访问器

摘要:为了理解get和set访问器,需要编写一个小程序来理解。1.只带有get器的属性称为只读属性。无法对只读属性赋值。 只带有set器的属性称为只写属性。只写属性除作为赋值的目标外,无法对其进行引用。 同时带有get和set器的属性为读写属性。 在属性声明中,get和set器都必须在属性体的内部声明。Program.cs 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 6 namespace fanwenqi 7 { 8 9 public ... 阅读全文
posted @ 2011-11-18 08:58 lovemu 阅读(1812) 评论(0) 推荐(0)
Visual C#(VS2008)制作DLL文件

摘要:一、制作.dll 1.首先创建一个新类库工程文件 文件->新建->项目->Visual C#->类库。 填入工程文件名称,并且选择文件要存放的目录。 2.工程文件 将Class1.cs改名自己要创建的文件名:Operate.cs,并填入代码。 3.生成DLL文件 生成->生成myDll.dll,最后会在工程文件的bin\debug目录里看到myDll.dll,文件扩展名是dll。Operate.cs 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using Sy 阅读全文
posted @ 2011-11-17 11:56 lovemu 阅读(3086) 评论(0) 推荐(0)

博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3