Introduction
I had a mocking interview at 10:00 pm, and I like to write Array.IndexOf but I need to search Google for the help. I asked myself why it is not array.IndexOf() instead of calling an abstract class Array.IndexOf assuming that array is an object of Array class.
Here is my C# practice. I has a few issues to use Array.IndexOf instead of using hashmap to save the index.
Understanding C# Array
I like to read a few articles to get more educated on C# Array.
Read c# Array -
Read 10 minutes - C# Arrays Tutorial
https://msdn.microsoft.com/en-us/library/aa288453(v=vs.71).aspx
20 minutes reading:
http://www.c-sharpcorner.com/article/working-with-arrays-in-C-Sharp/
Study stackoverflow posts related to C# Array -
More reading:
https://www.codeproject.com/Articles/6118/All-about-abstract-classes
Csharp 2000 things
Work on C# 2000 things, the following image is highlighted by search keyword: Array
Plan to spend 10 minutes for each item related to Array, some of them are Julia's favorites.
#136, Sorting an Array of Values Based on an Array
Julia's ranking: 10 out of 10
#135, Implementing IComparable to Allow Sorting a Custom Type
9 out 10
#137, Sorting an Array Using an Independent Comparer method
9 out 10
Actionable Items
Follow up
June 8, 2018
I spent over 20 minutes to look into more carefully about C# Array abstract class. It is true that Array.IndexOf is a static method, so that the call of the function should look like Array.IndexOf, instead of str.IndexOf. Compared to API SetValue as public function, it will be called differently.
My second question is why IndexOf API is static but SetValue is non-static. Maybe we can read Array C# class source and then figure out why.
More...C# Array examples
ReplyDelete