c# 之 3(string)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;




namespace ConsoleApplication_str
{
    class Program
    {
        static void Main(string[] args)
        {
            string str1 = "sjdk";
            string str2 = "sjdk";
            string str3 = "ajdk3";
            //相等
            int rtn1, rtn2;
            rtn1=str1.CompareTo(str2);
            rtn2=str3.CompareTo(str2);
            Console.WriteLine("CompareTo ****{0},{1}", rtn1,rtn2);
            rtn1= string.Compare(str1,str1);
            rtn2= string.Compare(str1, str2);
            Console.WriteLine("Compare ****{0},{1}", rtn1, rtn2);
            //string是否是引用类型
            string str;
            str = str1;
            Console.WriteLine("val type {0}*****,{1},{2}", typeof(string), str, str1);
            str1 = "sdgkadafaefe";
            Console.WriteLine( str);
            Console.WriteLine("\n");
            Console.WriteLine(str1);
            Console.WriteLine("\n");


            int a = 9;
            string stra;
            stra=string.Format("a's value:{0}", a);
            Console.WriteLine(stra);
            //数字转字符串
            Console.Write("数字转字符串");
            a = 13;
            Console.Write("16进制转换");
            stra = string.Format("a's xvalue:{0:x}", a);
            Console.WriteLine(stra);
            Console.Write("10进制转换");
            stra = string.Format("a's bvalue:{0:d}", a);
            Console.WriteLine(stra);


            Console.Write("16进制转换");
            Console.WriteLine(a.ToString("x"));
            Console.Write("10进制转换");
            Console.WriteLine(a.ToString());


            Console.Write("Convert 10进制转换");
            Console.WriteLine(Convert.ToString(a, 10));
            Console.Write("Convert 16进制转换");
            Console.WriteLine(Convert.ToString(a, 16));


            //字符串转数字
            Console.Write("字符串转数字");
            string strNum="1234567890";
            Console.WriteLine(Convert.ToInt32(strNum));
            //Console.WriteLine(Convert.ToByte(strNum));溢出
        
            strNum = "-1234567890";
            Console.WriteLine(Convert.ToInt32(strNum));
            strNum = "-1234567890";
            Console.WriteLine(Convert.ToDouble(strNum));




            for (int q = 0; q < 10000000; q++) ;
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值