2011年11月15日

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 阅读(117) 评论(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 阅读(112) 评论(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 阅读(175) 评论(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 阅读(222) 评论(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 阅读(105) 评论(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 阅读(76) 评论(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 阅读(101) 评论(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 阅读(112) 评论(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 阅读(184) 评论(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 阅读(105) 评论(0) 推荐(0)

导航