There are some issues with this function, some of them resulting from the fact that the task to be performed was poorly conceived to begin with.
The statement of the problem says that Ascii
Asciitakes a "one character string". You give it a character, not a one-character string.The whole notion of the Note that the
Asciifunction Ascii is dumb. Acompletely unnecessary: a character in the ASCII range is already a number representing its ASCII code. The function is completely unnecessary.The statement of the problem says that the function returns a string. You do that, but boy, is that dumbdoes not make good sense. Why on earth would you return a number as a string when you could return it as a number???
It's not the 1970's anymore. Stop thinking that strings contain ASCII. They contain Unicode.
"You may assume the initial string is not empty and contains several characters." Whoever posed the problem forgot that strings can be null.
I am thinking based on the incredible badness of the way the question is phrased, that whoever is posing you this question may not be an expert on C#. Consider taking a course from someone who is an expert on the subject matter.
Who said anything about a hash table size in the statement of the problem? This comes out of nowhere.
Good hash functions produce different values when given inputs are the same characters in a different order. Your hash function produces the same output for "12345", "54321", "51234", and so on. I made that mistake in a hash function once; the function was used to hash zip codes, and so of course most of them hashed to the same buckets. That was bad.
C# uses PascalCase for function names and magic constants. SHOUTY_SNAKE_CASE is for C programmers and Java programmers.
C# uses lowercase for formal parameters.
I am thinking based on the incredible badness of the way the question is phrased, that whoever is posing you this question may not be an expert on C#. Consider taking a course from someone who is an expert on the subject matter.