Maybe something like this:
static int Find(int el, int[] a)
{
int index = -1;
for (int i = 0; i < a.Length; i++)
{
if (a[i] == el)
{
return a[i];
}
}
return index;
}
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
You need to find an integer inside of an integer array?
Is there anything you're NOT allowed to use?
using System;
using System.Linq;
namespace DW_417111_CS_CON
{
class Program
{
static int find(int el, int[] a)
{
return a.ToList().IndexOf(el);
}
static void Main(string[] args)
{
int[] arr_int = new int[] { 5, 4, 6, 2, 9 };
Console.WriteLine(find(7, arr_int)); // prints -1
Console.WriteLine(find(6, arr_int)); // prints 2
}
}
}
thines01
Postaholic
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7
Thanks alot Mitja! I hope that this will work :) You are from slovenia like me? :)
yes :), Lj, but only live there.
So have you solved the issue?
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13