-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgo111.cs
32 lines (29 loc) · 876 Bytes
/
algo111.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace HelloWorld
{
class Program
{
public static string FindNeedle(object[] haystack)
{
/* int index = haystack.ToList().IndexOf(needle);
return index >= 0 ? $"found the needle at position {index}" : null;*/
int i = 0;
foreach (var item in haystack)
{
if (item == "needle")
{
return $"found the needle at position {i}";
}
i++;
}
return null;
}
static void Main(string[] args)
{
Console.WriteLine(FindNeedle(new object[] { '3', "123124234", null, "needle", "world", "hay", 2, '3', true, false }));
}
}
}