Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConConversion
- {
- class Program
- {
- //Again I needed to change this method to static method, so we can get input paramether from Main method
- //I didnt use Convert or Pharse, just simply use ASCII enconding
- //By ASCII enconding we are avoiding the undesirable characteristics
- //All will be changed to number even numbers
- //I am sure, that I could use here Try and Cath, and make exception (outOfRange) for undesirable characteristics
- //But still I think this is better way
- static public int ConvertToInt(string value)
- {
- int sum = 0;
- byte[] asciiBytes = Encoding.ASCII.GetBytes(value);
- foreach (byte b in asciiBytes)
- {
- //Writing each number for every characteristic
- Console.Write(b + ", ");
- //In the end I sum all numbers to one
- sum += b;
- }
- Console.WriteLine();
- Console.WriteLine("And the finally number is:" + sum);
- return sum;
- }
- static void Main(string[] args)
- {
- string value = "";
- Console.WriteLine("Write your numbers/characters.");
- value = Convert.ToString(Console.ReadLine());
- ConvertToInt(value);
- //I am sure, that I could by this check if are there any letter, if result==true, I shold close application.
- /*bool result = !value.Any(x => char.IsLetter(x));
- if (result == true)
- Console.WriteLine("True");
- else
- Console.WriteLine("False"); */
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement