学习C#中一些简单的方法使用

indexof(‘字符or字串’)查找字串中指定字符或字串首次出现的地方,并返回起索引;

Substring(int index ,int length)

index:开始的长度初始从0;

length:要截取的子字符串的长度;

using System;

namespace Sharp
{
    class Program
    {
        public static void Main(string[] args)
        {
            string mystring="Hello World";
            string subtring1=mystring.Substring(0);
            string subtring2=mystring.Substring(0,5);
            
            Console.WriteLine(subtring1);
            Console.WriteLine(subtring2);
            
            Console.ReadKey();
        }
    }
}

 Tostring(对象类名):把对象类名作为一个字符串返回;

 静态字段必须通过定义它的类来访问,不能用类的实例来访问

posted @ 2017-08-02 15:18  battly  阅读(359)  评论(0编辑  收藏  举报