去除串的重复单词,在C# [英] remove duplicate words from string in C#

查看:231
本文介绍了去除串的重复单词,在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的代码:

class Program
    {
        static void Main(string[] args)
        {
            string sentence = string.Empty;
            sentence = Console.ReadLine();
            string[] sent = sentence.Split(' ');
            //to be sorted alphabetically
            var x =
                from k in sent
                orderby k
                select k;

            foreach (string s in x)
            {
                    Console.WriteLine(s.ToLower());
            }

            Console.ReadLine();
        }
    }



有没有发现并删除重复的单词的方法或我应该让我自己的方法。

is there any method to find and remove duplicate words or I should make my own method?

推荐答案

使用鲜明的:

foreach (string s in x.Distinct())
{
        Console.WriteLine(s.ToLower());
}

这篇关于去除串的重复单词,在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆