博文

const c#(2007-10-13 20:49:00)

摘要:using System;
using System.Collections.Generic;
using System.Text; namespace __13
{
    class Program
    {
        static void Main(string[] args)
        {
            const int a = 12;
            const string b = "jack";
            const int c = a * 2;             modify(a, b);
            Console.WriteLine(a+"  "+b);
            Console.WriteLine(c);
        }         private static void modify(int a, string b)
     ......

阅读全文(1936) | 评论:0

c#方法参数(2007-10-13 20:12:00)

摘要:using System;
using System.Collections.Generic;
using System.Text;
using System.Collections; namespace __9
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 3;
            testprimitive(a);
            Console.WriteLine(a);              //3             ArrayList l = new ArrayList();
            Console.WriteLine(l.Count);            //0
           
 &n......

阅读全文(2052) | 评论:1

修饰符的一个例子new virtual override sealed(2007-10-13 19:02:00)

摘要://与java不同,c#不允许使用对象实例调用静态方法,让我惊讶啊!! //c++可不这样 using System;
using System.Collections.Generic;
using System.Text; namespace __5
{
    //class Program
    //{
    //    static void Main(string[] args)
    //    {     //    }
    //}     abstract public class person
    {
        string name;
        string ssn;
        int age;
        float salary;         public person(string name, string ssn, int age, float sal)
        {
            this.name = name;
          ......

阅读全文(1846) | 评论:0

学习C#静态函数及变量的一个精典例子(2007-10-13 15:27:00)

摘要://来自http://www.yaosansi.com/blog/article.asp?id=730 (1)用于对静态字段、只读字段等的初始化。              
(2)添加static关键字,不能添加访问修饰符,因为静态构造函数都是私有的。        
(3)类的静态构造函数在给定应用程序域中至多执行一次:只有创建类的实例或者引用类的任何静态成员才激发静态构造函数
(4)静态构造函数是不可继承的,而且不能被直接调用。            
(5)如果类中包含用来开始执行的 Main 方法,则该类的静态构造函数将在调用 Main 方法之前执行。    
    任何带有初始值设定项的静态字段,则在执行该类的静态构造函数时,先要按照文本顺序执行那些初始值设定项。  
(6)如果没有编写静态构造函数,而这时类中包含带有初始值设定的静态字段,那么编译器会自动生成默认的静态构造函数。

以下用例子代码进一步说明:

/**************************************************
*            静 态 构 造 函 数 练 习
* (1)①②③……为执行顺序
* (2)输出结果: static A()
*                 static B()
*                 X = 1, Y = 2
***************************************************/
using System;
class A
{
public static int ......

阅读全文(1550) | 评论:0

dataset 合并(2007-10-12 09:03:00)

摘要:using System;
using System.Collections.Generic;
using System.Text;
using System.Data; namespace merge
{
    class merge
    {
        static void Main(string[] args)
        {
            DataSet regularbooks = new DataSet("RegularBooks");
            DataSet bestsellers = new DataSet("BestSellers");             DataTable regulartable = new DataTable("books");
            DataTable sellertable = new DataTable("books");             DataColumn newcol = new DataColumn("ISBN",typeof(string));
            regulartable.Columns.Add(......

阅读全文(2750) | 评论:0

指向多个函数的委托(多播)(2007-09-29 20:41:00)

摘要:using System;
using System.Collections.Generic;
using System.Text; namespace _8_2
{
    class Program
    {
        public delegate float calcincome(float hourlywages);       
        public static readonly calcincome monthlyincome = new calcincome(person.calcmonthlyincome);
        public static readonly calcincome annualincome = new calcincome(person.calcannualincome);         public static readonly calcincome allincomes = monthlyincome + annualincome;         static void Main(string[] args)
        {
            try
            {
      &nbs......

阅读全文(1888) | 评论:0

作为静态成员的委托(2007-09-29 20:20:00)

摘要:using System;
using System.Collections.Generic;
using System.Text; namespace _8_2
{
    class Program
    {
        public delegate float calcincome(float hourlywages);         //委托可以打包成属性或者类的静态成员
        public static readonly calcincome monthlyincome = new calcincome(person.calcmonthlyincome);
        public static readonly calcincome annualincome = new calcincome(person.calcannualincome);
       
        static void Main(string[] args)
        {
            try
            {
              &nb......

阅读全文(2202) | 评论:0

委托中的异常处理(2007-09-29 20:07:00)

摘要:using System;
using System.Collections.Generic;
using System.Text; namespace _8_2
{
    class Program
    {
        public delegate float calcincome(string hourlywages);
         
        static void Main(string[] args)
        {
            calcincome del = new calcincome(person.calcannualincome);
            Console.WriteLine(del("hihg")); //委托中的异常处理?????,怎么处理
           
        }
    }     public class person
    {
        public float income;
     &nb......

阅读全文(1892) | 评论:0

委托入门例子(2007-09-29 19:56:00)

摘要:using System;
using System.Collections.Generic;
using System.Text; namespace _8_1
{
    class Program
    {
        public delegate float calcincome(float hourlywages); //  声明委托类型
        static void Main(string[] args)
        {
            calcincome del = new calcincome(person.calcannualincome); //实例化委托对象
            Console.WriteLine(del(26));                    //调用委托对象
            calcincome del2 = new calcincome(person.calcmonthlyincome);
            Console.WriteLine(del2(26));
  ......

阅读全文(1727) | 评论:0

浅析.Net下的多线程编程(2)(2007-09-23 20:14:00)

摘要://来自 http://developer.51cto.com/art/200509/3358_1.htm   线程优先级

一旦一个线程开始运行,线程调度程序就可以控制其所获得的CPU时间。如果一个托管的应用程序运行在Windows机器上,则线程调度程序是由Windows所提供的。在其他的平台上,线程调度程序可能是操作系统的一部分,也自然可能是.Net框架的一部分。不过我们这里不必考虑线程的调度程序是如何产生的,我们只要知道通过设置线程的优先级我们就可以使该线程获得不同的CPU时间。

线程的优先级是由Thread.Priority属性控制的,其值包含:ThreadPriority.Highest、ThreadPriority.AboveNormal、ThreadPriority.Normal、ThreadPriority.BelowNormal和ThreadPriority.Lowest。从它们的名称上我们自然可以知道它们的优先程度,所以这里就不多作介绍了。

线程的默认优先级为ThreadPriority.Normal。理论上,具有相同优先级的线程会获得相同的CPU时间,不过在实际执行时,消息队列中的线程阻塞或是操作系统的优先级的提高等原因会导致具有相同优先级的线程会获得不同的CPU时间。不过从总体上来考虑仍可以忽略这种差异。你可以通过以下的方法来改变一个线程的优先级。

thread.Priority = ThreadPriority.AboveNormal;

或是:

thread.Priority = ThreadPriority.BelowNormal;

通过上面的第一句语句你可以提高一个线程的优先级,那么该线程就会相应的获得更多的CPU时间;通过第二句语句你便降低了那个线程的优先级,于是它就会被分配到比原来少的CPU时间了。你可以在一个线程开始运行前或是在它的运行过程中的任何时候改变它的优先级。理论上你还可以任意的设置每个线程的优先级,不过一个优先级过高的线程往往会影响到其他线程的运行,甚至影响到其他程序的运行,所以最好不要随意的设置线程的优先级。

挂起线程和重新开始线程



Thread类分......

阅读全文(1607) | 评论:0