How to write function in .net6? [Answered]
I try .net6 for the first time and i got an error ask me to provide return value regardless that i already provided one.
![](https://utfs.io/f/6bab5901-59a9-475a-a034-f765d1863668-4pl4mu.png)
8 Replies
That only returns if the condition in the if statement is true. You need a return regardless of conditions.
like this ? but error still there
![](https://utfs.io/f/170e6ab5-1ba0-4267-9491-be35a5ffec89-4pl4mu.png)
No, because now the for loop will only run ones.
there is no guarantee that the code will enter the for loop
You need to add a return at the very end where it is not based on any conditions or anything. Sort of like fallback if everything else fails/doesn't run at least that will return.
sound like something in C
also,
.IndexOf
exists :)
✅ This post has been marked as answered!