C#基础--构造函数/析构函数/常用函数

1.构造函数与析构函数
   构造函数与析构函数都是系统自动调用的,相当与JAVA中的构造方法与垃圾回收器
2.常用函数
  ToString()//转换成字符串
  此外:Convert.ToBoolean(), Convert.ToChar(),Convert.ToDateTime(),Convert.ToDecimal(),Convert.ToInt32();
  eg: string myString = "ture";
        bool myBool =  Convert.ToBoolean(MyString);//将myBool转换成bool型
 3.字符串处理函数
   Length属性
   string mystr1 = "abABccDD";
   Console.WriteLine("{0}",mystr1.Lenth)//输出为8
   
   IndexOf方法
   string mystr1= "abABccDD";
   Console.WriteLine("{0}",mystr1.IndexOf("a"));//输出为0
   
   SubString()方法
  String myString = "abc";
   bool test1 = String.Compare(myString.SubString(2,1),"c") = =0;//it is ture
   bool test2 = String.Compare(mySring.SubString(3.0), String.Empty) = = 0;//this is ture

示例代码:

 1  using  System;
 2 
 3  public   class  Desk
 4  {
 5       private   int  weight;
 6       private   int  high;
 7 
 8       // define construction function
 9       public  Desk()
10      {
11          Console.WriteLine( " Constructing Desk " );
12          weight  =   6 ;
13          high  =   3 ;
14          Console.WriteLine( " weight = {0}\nhigh = {1} " ,weight,high);
15      }
16 
17       // destruction function
18       ~ Desk()
19      {
20          Console.WriteLine( " Destructing Desk " );
21      }
22 
23       public   static   void  Main()
24      {
25          Desk desk1  =   new  Desk();
26          Console.WriteLine( " back in main " );
27 
28           // DateTime t = DateTime.Today;
29          DateTime t  =  DateTime.Now;
30           // following is some time formation, using ToString("formationg") method imply
31          Console.WriteLine( " Now,date time is:{0} " ,t.ToString( " D " ));
32          Console.WriteLine( " Now,date time is:{0} " ,t.ToString( " d " ));
33          Console.WriteLine( " Now,date time is:{0} " ,t.ToString( " G " ));
34          Console.WriteLine( " Now,date time is:{0} " ,t.ToString( " g " ));
35          Console.WriteLine( " Now,date time is:{0} " ,t.ToString( " T " ));
36          Console.WriteLine( " Now,date time is:{0} " ,t.ToString( " t " ));
37      }
38  }



 

转载于:https://www.cnblogs.com/nut/archive/2007/05/24/758561.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值