找到 34423 篇文章 关于编程
1K+ 次浏览
要在 C# 中格式化输出,让我们看看格式化日期和双精度类型的示例。设置双精度类型的格式化输出。示例 在线演示using System; class Demo { public static void Main(String[] args) { Console.WriteLine("三位小数..."); Console.WriteLine(String.Format("{0:0.000}", 987.383)); Console.WriteLine(String.Format("{0:0.000}", 987.38)); Console.WriteLine(String.Format("{0:0.000}", 987.7899)); Console.WriteLine("千位分隔符..."); Console.WriteLine(String.Format("{0:0, 0.0}", 54567.46)); Console.WriteLine(String.Format("{0:0, 0}", 54567.46)); } }输出三位小数... 987.383 987.380 987.790 千位分隔符... 54, 567.5 54, 567设置 DateTime 的格式化输出示例 在线演示using System; static class Demo { static void Main() ... 阅读更多
1K+ 次浏览
我们的字符串是 − string str = " My make "; 使用以下正则表达式查找子字符串“make” @"\bmake\b" 这是完整的代码 − 示例 在线演示 using System; using System.Text.RegularExpressions; namespace RegExApplication { public class Program { private static void showMatch(string text, string expr) { Console.WriteLine("表达式: " + expr); MatchCollection mc = Regex.Matches(text, expr); ... 阅读更多
2K+ 次浏览
要在 C# 中使代码可重用,请使用接口。接口定义属性、方法和事件,这些是接口的成员。接口只包含成员的声明。派生类有责任定义成员。这通常有助于提供派生类将遵循的标准结构。例如,Shape 接口 −public interface IShape { void display(); }上面我们声明了一个接口 Shape。您可以注意到它以大写字母“I”开头。接口名称以“I”开头是一种常见的约定。我们没有在上面添加访问说明符... 阅读更多
14K+ 次浏览
设置列表 −List < string > list1 = new List < string > () { "Lawrence", "Adams", "Pitt", "Tom" };现在使用 Contains 方法检查项目是否存在于列表中。if (list1.Contains("Adams") == true) { Console.WriteLine("项目存在!"); }以下是检查 C# 列表中是否存在项目的代码。示例using System; using System.Collections.Generic; public class Program { public static void Main() { List < string > list1 = new List < string > () { "Lawrence", ... 阅读更多
16K+ 次浏览
使用 Contains() 方法检查字符串是否包含单词。设置字符串 −string s = "Together we can do so much!";现在假设您需要查找单词“much”if (s.Contains("much") == true) { Console.WriteLine("找到单词!"); }让我们看看完整的代码 −示例 在线演示using System; public class Demo { public static void Main() { string s = "Together we can do so much!"; if (s.Contains("much") == true) { Console.WriteLine("找到单词!"); } else { Console.WriteLine("未找到单词!"); } } }输出找到单词!
5K+ 次浏览
使用 Equals 方法检查 C# 数组中是否存在项目。设置字符串和子字符串 −string subStr = "pqrs"; string[] str = { "abcd", "ijkl", "pqrs", "wxyz" };现在使用 Equals 方法检查子字符串是否是字符串的一部分。if (item.Equals(subStr)) { Console.WriteLine("找到项目"); }这是完整的代码 −示例 在线演示using System; namespace Program { public class Demo { public static void Main(String[] args) { string subStr = "pqrs"; string[] str = { "abcd", "ijkl", "pqrs", "wxyz" }; foreach(string item in str) { if (item.Equals(subStr)) { Console.WriteLine("找到项目"); } } } } }输出找到项目
672 次浏览
要获取字符串中出现次数最多的字符,请循环到给定字符串的长度并查找出现次数。有了这个,设置一个新数组来计算 −for (int i = 0; i < s.Length; i++) a[s[i]]++; }我们上面使用的值 −String s = "livelife!"; int[] a = new int[maxCHARS];现在显示字符和出现次数 −for (int i = 0; i < maxCHARS; i++) if (a[i] > 1) { Console.WriteLine("字符 " + (char) i); Console.WriteLine("出现次数 = " + a[i] + " 次"); }让我们看看完整的代码 ... 阅读更多
673 次浏览
要显示多行空行,我们将使用 while 循环。在这里,我们使用 Console.WriteLine(); 打印 10 行空行while (a < 10) { Console.WriteLine(" "); a++; }以下是显示多行空行的完整代码 −示例using System; namespace Program { public class Demo { public static void Main(String[] args) { int a = 0; while (a < 10) { Console.WriteLine(" "); a++; } Console.WriteLine("上面显示了 10 行空行!"); Console.ReadLine(); } } }
638 次浏览
要显示一行,在 C# 中使用 Console.Write()。Console 在控制台中显示结果。我首先设置了一个字符串。string str = "Tom Hanks is an actor";现在显示上面的行。Console.WriteLine(str);以下是完整的代码 −示例 在线演示using System; namespace Program { public class Demo { public static void Main(String[] args) { string str = "Tom Hanks is an actor"; Console.WriteLine("下面显示一行"); Console.WriteLine(str); Console.ReadLine(); } } }输出下面显示一行 Tom Hanks is an actor
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP