c#基础3

来源:互联网 发布:最新3d网络游开服时间 编辑:程序博客网 时间:2024/05/16 15:34
1.关键字
class Program    {        static void Main(string[] args)        {            //能够修饰类的访问修饰符:internal(在当前项目中都可以访问) public            //子类的访问权限不能高于父类            //proteced 只能在类及子类中访问            //不同项目间访问需要添加引用并包含命名空间            //关键字            //1.this base new virtual abstract override interface partial sealed static            //this 1.当前类的对象 2.调用自己的构造函数            //base 调用父类成员            //new 1.创建对象 2.隐藏父类的成员            //partial 部分类(用来修饰类,合起来是一个完整的类,且成员都是共享的)            //sealed 密封类(用来修饰类,密封类不可以被继承,但是可以继承于其他类)            //static 静态类不能创建对象,可以直接调用方法        }    }


2.字符串操作函数

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _20151027{    class Program    {        static void Main(string[] args)        {            //GC垃圾回收  c#自动            //文件流GC无法自动回收  需要写在using中            //字符串的不可变性,重新开辟空间???            //string s1 = "张三";            //            //s1 = "李西";            //字符串可以看成类型为char的只读数组            //用下标访问时返回的是char类型                        //char[] chs = s1.ToCharArray();            //转成字符数组后可以修改它            //chs[0]='a';            //s1 = new string(chs);            //if (string.IsNullOrEmpty(s1))            //{            //    Console.WriteLine("yes");            //}            //else            //{            //    Console.WriteLine("no");            //}            //Substring:截取字符串 string sNew=s.Substring(3,1) 第二个参数不写则默认截取到最后            //IndexOf:字符串中某个字母第一次出现的位置,不出现返回-1            //LastIndexOf:字符串中某个字母最后一次出现的位置,不出现返回-1            //string s1 = "c#";            //string s2 = "C#";            //if (s1.Equals(s2))            //{            //    Console.WriteLine("相同");            //}            //else            //{            //    Console.WriteLine("不相同");            //}            //string str = "abcd, , fd, fdasdf [][]";            ////Split:分割字符串(这个用的不熟)            //string[] strNew= str.Split(new char[] { ',', ' ', '[', ']' }, StringSplitOptions.RemoveEmptyEntries);            //join:指定的元素放在数组成员后面            //string[] names = { "kyle", "nestle", "kaka", "cr" };            //string s = string.Join("|", names);            //Console.WriteLine("s");            //Console.ReadKey();            //Repalce:替换            string str = "美国太平洋";            str = str.Replace("美国","**");            Console.WriteLine(str);            Console.ReadKey();            //Trim:去掉字符串两端的空格  TrimEnd  TrimStart            //  string s = " from dual union all ";            //s = s.Trim().TrimEnd("union all".ToCharArray());结果是:from d        }    }}


0 0