gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 11:24:38 26 4
gpt4 key购买 nike

我有一个程序,如下所示

我做了这个方法,但我想在控制台中显示它而不是像 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com