2011年11月15日

EventEmail

摘要: using System;using System.Collections.Generic;using System.Text;using System.Windows.Forms;namespace EventEmail{ public class MailData { public readonly string from, to, subject, body; public MailData(string from, string to, string subject, string body) { this.from = from; this.to = to; this.subject 阅读全文

posted @ 2011-11-15 22:43 breakpoint 阅读(154) 评论(0) 推荐(0) 编辑

EventExample1

摘要: using System;namespace EventExample1{ public delegate void ChangedEventHandler(object sender, EventArgs e); public class MyText { public event ChangedEventHandler Changed; protected virtual void OnChanged() { if (Changed != null) { Changed(this, null); } } private string _text = string.Empty; public 阅读全文

posted @ 2011-11-15 22:43 breakpoint 阅读(114) 评论(0) 推荐(0) 编辑

OperationDelegate

摘要: using System;namespace DelegateSample1{ //define delegate public delegate int OperationDelegate(int x, int y); class Operator { private int _x, _y; static void Main(string[] args) { OperationDelegate del = null; del += new OperationDelegate(Plus); del += new OperationDelegate(Subtract); Operator op 阅读全文

posted @ 2011-11-15 22:40 breakpoint 阅读(117) 评论(0) 推荐(0) 编辑

WinLogs

摘要: using System.Diagnostics;using System;namespace ConsoleApplication1{ class WinLogs { private static void Main44() { EventLog log = new EventLog("MyEvent"); //System 默认是Application // 首先应判断日志来源是否存在,一个日志来源只能同时与一个事件绑定 if (!EventLog.SourceExists("MyApplicationCCC")) //向非Application事件 阅读全文

posted @ 2011-11-15 22:38 breakpoint 阅读(142) 评论(0) 推荐(0) 编辑

Yield

摘要: //Copyright (C) Microsoft Corporation. All rights reserved.using System;using System.Collections.Generic;using System.Text;namespace Yield{ class Yield { public static class NumberList { // Create an array of integers. public static int[] ints = { 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377 }; 阅读全文

posted @ 2011-11-15 22:36 breakpoint 阅读(195) 评论(0) 推荐(0) 编辑

TestWhere

摘要: using System;using System.Collections;using System.Collections.Generic;using System.Linq;namespace ConsoleApplication1{ //在定义泛型类时,可以对客户端代码能够在实例化类时用于类型参数的类型种类施加限制。如果客户端代码尝试使用某个约束所不允许的类型来实例化类,则会产生编译时错误。这些限制称为约束。约束是使用 where 上下文关键字指定的。 // 从 Visual C# 3.0 开始,在方法范围中声明的变量可以具有隐式类型 var。 隐式类型的本地变量是强类型变量(就好像您已 阅读全文

posted @ 2011-11-15 22:35 breakpoint 阅读(109) 评论(0) 推荐(0) 编辑

ThreadingTester

摘要: using System;using System.Threading;namespace ThreadingTester{ class ThreadingTester { public static void trmain() { for (int x = 0; x < 100; x++) { Thread.Sleep(1000); Console.WriteLine(x); } } static void Main(string[] args) { Thread thrd1 = new Thread(new ThreadStart(trmain)); thrd1.Start(); f 阅读全文

posted @ 2011-11-15 22:35 breakpoint 阅读(87) 评论(0) 推荐(0) 编辑

ThreadClass

摘要: using System;using System.Threading;using System.Linq;using System.Collections.Generic;namespace ThreadingTester{ /*“Lambda 表达式”是一个匿名函数,它可以包含表达式和语句,并且可用于创建委托或表达式目录树类型。 所有 Lambda 表达式都使用 Lambda 运算符 =>,该运算符读为“goes to”。该 Lambda 运算符的左边是输入参数(如果有),右边包含表达式或语句块。 => 标记称作 lambda 运算符。该标记在 lambda 表达式中用来将左侧 阅读全文

posted @ 2011-11-15 22:35 breakpoint 阅读(213) 评论(0) 推荐(0) 编辑

TestGenericClass

摘要: using System;using System.Collections.Generic;namespace ConsoleApplication1{ public interface IAccount { string Name { get; } decimal Balance { get; } } public class Account : IAccount { private string name; public string Name { get { return name; } } private decimal balance; public decimal Balance 阅读全文

posted @ 2011-11-15 22:34 breakpoint 阅读(107) 评论(0) 推荐(0) 编辑

MultiThread

摘要: using System;using System.Threading;namespace MultiThread{ public class Program { static ManualResetEvent mre = new ManualResetEvent(false); static void Main77() { Thread t = new Thread(new ThreadStart(Hello)); t.Start(); while (true) { char a = Console.ReadKey().KeyChar; if (a.ToString().ToUpper() 阅读全文

posted @ 2011-11-15 22:33 breakpoint 阅读(171) 评论(0) 推荐(0) 编辑

LINQ

摘要: using System;using System.Collections.Generic;using System.Data.Linq;using System.Data.Linq.Mapping;using System.Data.Linq.SqlClient;using System.Linq;using System.IO;namespace ThreadingTester{ [Table(Name = "Customers")] public class Customer { [Column(IsPrimaryKey = true)] public string 阅读全文

posted @ 2011-11-15 22:33 breakpoint 阅读(217) 评论(0) 推荐(0) 编辑

Generic

摘要: using System;using System.Collections.Generic;namespace ConsoleApplication1{ class Generic { static void Main11(string[] args) { PrintAll2<int>(3); PrintAll2<string>("c"); PrintAll2(4); PrintAll2("d"); PrintAll2(5.5); Console.ReadLine(); } static void PrintAll2<T&g 阅读全文

posted @ 2011-11-15 22:31 breakpoint 阅读(98) 评论(0) 推荐(0) 编辑

GenericClassInherit

摘要: using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{ class GenericClassInherit { //C# 编译器只允许将泛型参数隐式强制转换到 Object 或约束指定的类型 public interface ISomeInterface { } class BaseClass { } class MyClass<T> where T : BaseClass, ISomeInterface { vo 阅读全文

posted @ 2011-11-15 22:31 breakpoint 阅读(73) 评论(0) 推荐(0) 编辑

GetURLAsync

摘要: using System;using System.IO;using System.Net;using System.Threading;/// <summary>/// 使用异步机制的例子/// </summary>public class CAsync{ const int MAX = 1024; public static int Main88() { Uri HttpSite; HttpWebRequest wreq; IAsyncResult r; HttpSite = new Uri("http://localhost"); wreq = 阅读全文

posted @ 2011-11-15 22:31 breakpoint 阅读(99) 评论(0) 推荐(0) 编辑

Flower

摘要: using System;using System.Threading;public class TestMain{ private static ManualResetEvent ent = new ManualResetEvent(false); public static void Main33() { Boy sender = new Boy(ent); //Thread th = new Thread(new ThreadStart(sender.SendFlower)); //th.Start(); //ent.WaitOne(); //等待工作 for (int i = 0; . 阅读全文

posted @ 2011-11-15 22:30 breakpoint 阅读(105) 评论(0) 推荐(0) 编辑

BeginInvoke

摘要: using System;using System.Threading;namespace ConsoleApplication1{ class BeginInvoke { private delegate int NewTaskDelegate(int ms); static void Main44() { NewTaskDelegate task = new NewTaskDelegate(newTask);//委托实例 IAsyncResult asyncResult = task.BeginInvoke(2000, new AsyncCallback(CallBackMethod11) 阅读全文

posted @ 2011-11-15 22:29 breakpoint 阅读(409) 评论(0) 推荐(0) 编辑

CalculateTest

摘要: using System;using System.Threading;class CalculateTest{ static void Main11() { Calculate calc = new Calculate(); Console.WriteLine("Result = {0}.",calc.Result(234).ToString()); Console.WriteLine("Result = {0}.",calc.Result(55).ToString()); }}class Calculate{ double baseNumber, f 阅读全文

posted @ 2011-11-15 22:29 breakpoint 阅读(99) 评论(0) 推荐(0) 编辑

CallBackMethod

摘要: using System;namespace ConsoleApplication1{ class CallBackMethod { private delegate string DelegateName(int Num, out int Num2); private static string MethodName11(int Num, out int Num2) { Num2 = Num; return "HelloWorld"; } //异步完成时,执行的方法(回调方法),此方法只能有IAsyncResult一个参数,但是该参数几乎万能,可以传递object pri 阅读全文

posted @ 2011-11-15 22:29 breakpoint 阅读(175) 评论(0) 推荐(0) 编辑

IsTestedAttribute

摘要: //Copyright (C) Microsoft Corporation. All rights reserved.// AttributesTutorial.cs// This example shows the use of class and method attributes.using System;using System.Reflection;using System.Collections;// The IsTested class is a user-defined custom attribute class.// It can be applied to any dec 阅读全文

posted @ 2011-11-15 22:28 breakpoint 阅读(92) 评论(0) 推荐(0) 编辑

AttributesSample.

摘要: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Reflection;namespace ConsoleApplication1{ /// <summary> /// AttributeTargets.Class表示我们自定义的属性只能用于类上。 /// </summary> [AttributeUsage(AttributeTargets.Class)] public class MyCustomAttribute : Attr 阅读全文

posted @ 2011-11-15 22:28 breakpoint 阅读(89) 评论(0) 推荐(0) 编辑

导航