Category: C# Questions

How to Create Text File in C#/CSharp

To create a text file in C#/CSharp, we make use of File class which contains Create static function.  This function will take text file path as parameter where you want to create the text file. using System; using System.IO; namespace Hello_World { class Program { static void Main(string args) { string file = @"C:\Users\ADMIN\Desktop\file.txt"; File.Create(file);

How to Split a String in C#/CSharp

To split a string in C#/CSharp, we make use of Split method.  This will take a character as parameter to split.  In the below given example, we are passing an empty space as parameter. using System; namespace Hello_World { class Program { static void Main(string args) { string hello = "I love making tutorials."; string

How to Sort An Array in C#/CSharp

For sorting an array in C#/CSharp, we make use of static method called sort which resides in Array class.  Example is given below. using System; namespace Hello_World { class Program { static void Main(string args) { int array = { 9, 8, 7, 4, 3 }; Console.WriteLine("Before Sorting"); foreach (int i in array) { Console.WriteLine(i);