摘要: 在 C# 语言中数据类型分为值类型和引用类型,将值类型转换为引用类型的操作称为装箱,相应地将引用类型转换成值类型称为拆箱。 C# ToString 方法用于将任意的数据类型转换成字符串类型,例如将整数类型转换成字符串类型。 int a=100; string str=a.ToString(); // 阅读全文
posted @ 2019-12-23 15:54 highlightyys 阅读(48) 评论(0) 推荐(0)
摘要: C# Convert 方法是数据类型转换中最灵活的方法,它能够将任意数据类型的值转换成任意数据类型,前提是不要超出指定数据类型的范围。 具体的语法形式如下。 数据类型 变量名 = convert.To数据类型(变量名); 这里 Convert.To 后面的数据类型要与等号左边的数据类型相匹配。 方法 阅读全文
posted @ 2019-12-23 15:50 highlightyys 阅读(124) 评论(0) 推荐(0)
摘要: C# Parse 方法用于将字符串类型转换成任意类型,具体的语法形式如下。 数据类型 变量 = 数据类型.Parse(字符串类型的值); 这里要求等号左、右两边的数据类型兼容。 int num1 = int.Parse(Console.ReadLine()); int num2 = int.Pars 阅读全文
posted @ 2019-12-23 14:15 highlightyys 阅读(55) 评论(0) 推荐(0)
摘要: class Program { static void Main(string[] args) { string str = Console.ReadLine(); str = str.Insert(1, "@@@"); Console.WriteLine("新字符串为:" + str); } } 阅读全文
posted @ 2019-12-23 13:40 highlightyys 阅读(661) 评论(0) 推荐(0)
摘要: class Program { static void Main(string[] args) { string str = Console.ReadLine(); int firstIndex = str.IndexOf("@"); int lastIndex = str.LastIndexOf( 阅读全文
posted @ 2019-12-23 13:38 highlightyys 阅读(61) 评论(0) 推荐(0)
摘要: class Program { static void Main(string[] args) { string str = Console.ReadLine(); if (str.IndexOf(",") != -1) { str = str.Replace(",", "_"); } Consol 阅读全文
posted @ 2019-12-23 10:12 highlightyys 阅读(70) 评论(0) 推荐(0)
摘要: 使用 IndexOf 方法查找第一个 @ 出现的位置与使用 LastlndexOf 方法查找 @ 在字符串中最后一次出现的位置相同即可 class Program { static void Main(string[] args) { string str = Console.ReadLine(); 阅读全文
posted @ 2019-12-23 10:09 highlightyys 阅读(25) 评论(0) 推荐(0)