# Help with Exercise from Ultimate C# Series: Part 1

**URL:** <https://forum.codewithmosh.com/t/help-with-exercise-from-ultimate-c-series-part-1/20862>\
**Category:** C#\
**Created:** [June 17, 2023, 2:37am UTC](https://forum.codewithmosh.com/t/help-with-exercise-from-ultimate-c-series-part-1/20862 "2023-06-17T02:37:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![atezian](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@atezian](https://forum.codewithmosh.com/u/atezian)\
**Post date:** [June 17, 2023, 2:37am UTC](https://forum.codewithmosh.com/t/help-with-exercise-from-ultimate-c-series-part-1/20862/1 "2023-06-17T02:37:38Z")

</div>

**My question:**  
Why doesn’t Mosh use split to remove the spaces? He only uses split to remove to commas which I assume leaves a string with numbers separated by spaces. I don’t understand this.

**Context:**  
In Control Flow the second exercises has a question:

Write a program and ask the user to enter a series of numbers separated by comma. Find the maximum of the numbers and display it on the result. For example, if the user enters “5, 3, 8, 1, 4", the program should display 8 on the console.

In Mosh’s answer he does this:

```auto
public void Exercise5()
        {
            Console.Write("Enter commoa separated numbers: ");
            var input = Console.ReadLine();

            var numbers = input.Split(',');

            // Assume the first number is the max 
            var max = Convert.ToInt32(numbers[0]);

            foreach (var str in numbers)
            {
                var number = Convert.ToInt32(str);
                if (number > max)
                    max = number;
            }

            Console.WriteLine("Max is " + max);

        }

```

---

<div class="post-metadata">

**Author:** ![UniqueNospaceShort](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/uniquenospaceshort/32/1814_2.png) [@UniqueNospaceShort](https://forum.codewithmosh.com/u/UniqueNospaceShort)\
**Post date:** [June 17, 2023, 4:06pm UTC](https://forum.codewithmosh.com/t/help-with-exercise-from-ultimate-c-series-part-1/20862/2 "2023-06-17T16:06:19Z")

</div>

Hi,

An `int` has no space to worry about.

Just update the code a bit and see for yourself.

```auto
using System;
					
public class Program
{
	public static void Main()
	{
            Console.Write("Enter commoa separated numbers: ");
            //var input = Console.ReadLine();
			var input = "8, 12 , 1,4, 6, 16, 9 ,0";

            var numbers = input.Split(',');

            // Assume the first number is the max 
            var max = Convert.ToInt32(numbers[0]);

            foreach (var str in numbers)
            {
                var number = Convert.ToInt32(str);
				Console.WriteLine($"|{str}| =>|{number}|");
                if (number > max)
                    max = number;
            }

            Console.WriteLine("Max is " + max);
	}
}

```

> Output

```auto
Enter commoa separated numbers: |8| =>|8|
| 12 | =>|12|
| 1| =>|1|
|4| =>|4|
| 6| =>|6|
| 16| =>|16|
| 9 | =>|9|
|0| =>|0|
Max is 16

```

---

<div class="post-metadata">

**Author:** ![atezian](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@atezian](https://forum.codewithmosh.com/u/atezian)\
**Post date:** [June 18, 2023, 4:22am UTC](https://forum.codewithmosh.com/t/help-with-exercise-from-ultimate-c-series-part-1/20862/4 "2023-06-18T04:22:33Z")

</div>

Thanks. Why doesn’t int have no space to worry about? In a previous lesson we learnt that all character symbols are numbers for ascii. I looked up the ascii value for space and it is 32.

---

<div class="post-metadata">

**Author:** ![UniqueNospaceShort](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/uniquenospaceshort/32/1814_2.png) [@UniqueNospaceShort](https://forum.codewithmosh.com/u/UniqueNospaceShort)\
**Post date:** [June 18, 2023, 12:37pm UTC](https://forum.codewithmosh.com/t/help-with-exercise-from-ultimate-c-series-part-1/20862/5 "2023-06-18T12:37:03Z")

</div>

Hi,  
Space is a character.  
`int` is a number (integer) so, it simply keeps just the number information. There is no white space in there.  
So what I mean by “no space to worry about” is simply that when we convert from `string` to `int`, any white-space is removed. This is what we can see in the sample output I did add in my previous answer.

The other thing you are talking about is how letters are actually corresponding to ASCII or Unicode tables.

A computer basically doesn’t know what A,a,B and b are. But it can deal with numbers (binary based). So letters are actually corresponding to numbers and represented on screen as characters.

If you want to know more on the details please refer to those standards I mentioned above.

Cheers.

---

<div class="post-metadata">

**Author:** ![atezian](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@atezian](https://forum.codewithmosh.com/u/atezian)\
**Post date:** [June 20, 2023, 4:12am UTC](https://forum.codewithmosh.com/t/help-with-exercise-from-ultimate-c-series-part-1/20862/6 "2023-06-20T04:12:10Z")

</div>

Perhaps I am getting confused with casting a space character to an int versis Convert.ToInt32.
