Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> numbers = new List<int>();
- //Reading the line containing comma seperated integers list
- var line = Console.ReadLine();
- //Splitting to get individual integers
- var lineNumbers = line.Split(',');
- foreach (var item in lineNumbers)
- {
- //Adding them to list as list supports Sort() function
- numbers.Add(Convert.ToInt32(item));
- }
- //Sorting the list
- numbers.Sort();
- //Printing first number
- Console.Write(numbers[0]);
- numbers.RemoveAt(0);
- //All further numbers we are printing preceded with comma
- numbers.ForEach(i => Console.Write("," + i));
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment