找到 34423 篇文章,关于编程

C# 中的格式化输出

George John
更新于 2020-06-22 09:26:01

1K+ 次查看

要格式化 C# 中的输出,让我们看看格式化日期和双精度类型的示例。设置双精度类型的格式化输出。示例 实时演示使用 System;类 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 的格式化输出示例 实时演示使用 System;静态类 Demo {    static void Main() ... 阅读更多

如何在 C# 中使用正则表达式查找匹配的子字符串?

Samual Sam
更新于 2019-07-30 22:30:23

1K+ 次查看

我们的字符串是 - string str = " My make "; 使用以下正则表达式查找子字符串“make” @"\bmake\b" 这是完整的代码 - 示例实时演示使用 System;使用 System.Text.RegularExpressions;命名空间 RegExApplication { 公共类程序 { 私有静态 void showMatch(string text, string expr) { Console.WriteLine("表达式:"+ expr); MatchCollection mc = Regex.Matches(text, expr); ... 阅读更多

如何在 C# 中使代码可重用?

Chandu yadav
更新于 2020-06-22 09:27:05

2K+ 次查看

要使 C# 中的代码可重用,请使用接口。接口定义属性、方法和事件,这些是接口的成员。接口仅包含成员的声明。派生类负责定义成员。它通常有助于提供派生类将遵循的标准结构。例如,Shape 接口 -public interface IShape {    void display(); }上面我们声明了一个接口 Shape。您可以注意到它以大写字母“I”开头。接口名称以“I”开头是一种常见约定。我们上面没有添加访问说明符... 阅读更多

如何检查 C# 列表集合中是否存在某个项目?

Arjun Thakur
更新于 2020-06-22 09:09:58

14K+ 次查看

设置一个列表 -List < string > list1 = new List < string > () {    "Lawrence",    "Adams",    "Pitt",    "Tom" };现在使用 Contains 方法检查列表中是否存在某个项目。if (list1.Contains("Adams") == true) {    Console.WriteLine("项目存在!"); }以下是检查 C# 列表中是否存在某个项目的代码。示例使用 System;使用 System.Collections.Generic;公共类程序 {    public static void Main() {       List < string > list1 = new List < string > () {          "Lawrence",   ... 阅读更多

理解 C# 中的逻辑回归

karthikeya Boyini
更新于 2020-06-22 09:27:23

288 次查看

逻辑回归是一种用于二项式回归的线性模型。它用于医学科学以及预测客户购买产品的倾向。它为此目的使用预测变量。逻辑回归允许以优势比和统计假设检验的形式更轻松地分析结果。广义线性模型已将输入用于非线性链接函数。线性模型具有以下形式:z = c1x1 + c2x2 + … cnxn + i = ct x + i这里,c 是系数向量,i 是截距值 x 是观测向量

如何在 C# 中检查字符串是否包含某个单词?

Samual Sam
更新于 2020-06-22 09:12:21

16K+ 次查看

使用 Contains() 方法检查字符串是否包含某个单词。设置字符串 -string s = "Together we can do so much!";现在假设您需要查找单词“much”if (s.Contains("much") == true) {    Console.WriteLine("找到单词!"); }让我们看看完整的代码 -示例 实时演示使用 System;公共类 Demo {    public static void Main() {       string s = "Together we can do so much!";       if (s.Contains("much") == true) {          Console.WriteLine("找到单词!");       } else {          Console.WriteLine("未找到单词!");       }    } }输出找到单词!

如何在 C# 数组中检查项目是否存在?

Ankith Reddy
更新于 2020-06-22 09:11:45

5K+ 次查看

使用 Equals 方法检查 C# 数组中是否存在某个项目。设置字符串和子字符串 -string subStr = "pqrs"; string[] str = {    "abcd",    "ijkl",    "pqrs",    "wxyz" };现在使用 Equals 方法检查子字符串是否是字符串的一部分。if (item.Equals(subStr)) {    Console.WriteLine("找到项目"); }这是完整的代码 -示例 实时演示使用 System;命名空间程序 {    公共类 Demo {       公共静态 void Main(String[] args) {          string subStr = "pqrs";          string[] str = {             "abcd",             "ijkl",             "pqrs",             "wxyz"          };          foreach(string item in str) {             if (item.Equals(subStr)) {                Console.WriteLine("找到项目");             }          }       }    } }输出找到项目

C# 程序获取字符串中出现次数最多的字符

karthikeya Boyini
更新于 2020-06-22 09:13:02

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] + " 次");    }让我们看看完整的代码 ... 阅读更多

如何在 C# 中打印多行空白行?

George John
更新于 2020-06-22 09:14:20

673 次查看

要显示多行空白行,我们将使用 while 循环。这里,我们使用 Console.WriteLine() 打印 10 行空白行;while (a < 10) {    Console.WriteLine(" ");    a++; }以下是显示多行空白行的完整代码 -示例使用 System;命名空间程序 {    公共类 Demo {       公共静态 void Main(String[] args) {          int a = 0;          while (a < 10) {             Console.WriteLine(" ");             a++;          }          Console.WriteLine("上面显示了 10 行空白行!");          Console.ReadLine();       }    } }

如何使用 C# 在控制台上打印一行?

Chandu yadav
更新于 2020-06-22 09:16:02

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("Displaying a line below");          Console.WriteLine(str);          Console.ReadLine();       }    } }输出Displaying a line below Tom Hanks is an actor

广告
© . All rights reserved.