使用 C#,您可以轻松显示以下菱形形状。$ $$$ $$$$$ $$$$$$$ $$$$$$$$$ $$$$$$$ $$$$$ $$$ $要显示菱形,您需要关注以下几点:- 行数 - 要显示的美元符号数量 - 空格数量考虑到以上几点,您可以轻松创建如下代码所示的菱形形状:示例 在线演示using System; namespace Program { public class Demo { public static void Main(String[] args) { int i, j, r, d, e; // 行数 = 5 r = 5; // 显示美元符号 d = 1; // 空格 e = r - 1; for (i = 1; i < r * 2; i++) { // 显示空格 for (j = 1; j
要在字符串中查找数字,请使用正则表达式。我们已设置正则表达式模式以从字符串中获取数字。Regex r = new Regex(@"\d+");现在,使用 C# 中的 Match 类来设置字符串。Match m = r.Match("Welcome! We are open 365 days in a year!");现在使用 Success 属性来显示如果在字符串中找到数字的结果,如下面的完整代码所示:示例 在线演示using System; using System.Text.RegularExpressions; class Demo { static void Main() { Regex r = new Regex(@"\d+"); Match m = r.Match("Welcome! We are open ... 阅读更多