[英]C#: A method that returns true if the value 3 is contained in the array and false otherwise
I'm trying to translate 我正在尝试翻译
"A method that returns true if the value 3 is contained in the array and false otherwise." “如果数组中包含值3,则返回true,否则返回false。
into code, but so far the only thing I could come up with is 到代码中,但到目前为止,我唯一能想到的是
class Test
{
static void Main(string[] args)
{
ValueThree();
}
static bool ValueThree()
{
int[] arr = { 1, 2, 3 };
if (Array = 3)
}
return true;
}
Not really sure where do go from here, any feedback would be much appreciated. 不太确定从何而来,我们将不胜感激。
An C#-Array implements the IEnumerable<TSource>
interface. C#数组实现IEnumerable<TSource>
接口。 One of the defined methods on this interface is the Contains(TSource element)
method which checks if the element is in the collection of elements. 这个接口上定义的方法之一是Contains(TSource element)
方法,该方法检查该元素是否在元素集合中。
So in your case it should be: 因此,在您的情况下应该是:
static bool ValueThree()
{
int[] arr = { 1, 2, 3 };
return arr.Contains(3);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.