c# - 如何在 C# 中显示我的结果?

标签 c# console.writeline

我有一个程序,如下所示

我做了这个方法,但我想在控制台中显示它 而不是像 console.writeline(str.length) 这样简单的方法。我想使用我制作的方法。

有人可以帮我吗

提前致谢

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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "dit is een test 1,2,3";
            Console.WriteLine(str);
        }

        public int CountAllNumbersAndChar(string str) 
        { 
            return str.Length; 
        }

    }
}

更新:

我现在有以下程序

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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "this is a test 1,2,3";
            int length = CountAllNumbersAndChar(str);
            Console.WriteLine(str);
            Console.WriteLine(length);// met de methode maar kan handiger met onderstaand voor beeld
      // Console.WriteLine(str.Length);
       // int numbers = str.Count(Char.IsNumber); // de makelijkste makelijke manier 
        //Console.WriteLine(numbers);
        int countnumber = CountNumbers(str) ;
        Console.WriteLine(countnumber);
        int countwords = words(str);
        Console.WriteLine(countwords);


    }

    public static int CountAllNumbersAndChar(string str)
    {
        return str.Length;
    }
    public static int CountNumbers(string str)
    {
        return str.Count(Char.IsNumber);
    }
    public static int words(string str)
    {
        int words = str.Split().Count(str => str.All(Char.IsLetter));
    }
}

}

但是还是不行 有人可以告诉我我必须改变什么吗?

最佳答案

这是你想要的吗?

Console.WriteLine(CountAllNumbersAndChar(str));

关于c# - 如何在 C# 中显示我的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1480735/

相关文章:

c# - 双重数据认可?

c# - Entity Framework - 在连接上使用导航属性

c# - 没有控制台时如何找到 Console.WriteLine() 值?或者如何在没有控制台的情况下在运行时打印出值。

c# - 对齐控制台输出的文本?

c# - (Console.BufferHeight) 我无法使用 Console.WriteLine 看到/滚动查看所有控制台输出

c# - 如何在c#中声明动态数组

c# - 我需要深拷贝吗?

c# - 使用正则表达式将插值字符串转换为 string.Format

c# - 有没有办法删除刚刚使用 Console.WriteLine 写入的字符?

c# - foreach 循环与正则表达式匹配问题