0
点赞
收藏
分享

微信扫一扫

C# 用列表实现挑选区间内的数字

q松_松q 2022-07-14 阅读 15


using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
class Program
{
static void Main(String[] args)
{
//记录数组
var a = new int[20];
var s = Console.ReadLine().Split(" ");
var list = new List<int>();
for(int i = 0; i < s.Length; i++)
{
var data = Convert.ToInt32(s[i]);
if(data >0 &&data<100 && !list.Exists(x => x == data))
{
list.Add(data);
}
}
foreach( var item in list)
{
Console.Write("{0} ", item);
}
Console.ReadLine();// 程序运行就会停下来,等待输入,这样就可以看到输出结果
}
}
}

C# 用列表实现挑选区间内的数字_c#


1.怎么查看元素类型:GetType() 方法

2、var类型:推断类型(其实也就是弱化类型的定义)

IDE或编译器会根据你给变量的值,来"推论,断定"a的类型.

​​更多:​​ 3.C#中List集合使用Exists方法判断是否存在符合条件的元素对象

list.Exists(x => x == data)


举报

相关推荐

0 条评论