To generate a random number in C#/CSharp, we make use of Random class. You can pass min and max value as parameter to its method called Next which will a generate number. The generated number will be within a range from min value and less than max value. This means max value will not be
To get host name of the local computer, we make use of GetHostName() method which resides in Dns class. Dns class is part of System.Net space. Example is given below. using System; using System.Net; namespace Hello_World { class Program { static void Main(string args) { string hostname = Dns.GetHostName(); Console.WriteLine(hostname); } } }
To trim a string in C#/CSharp, we make use of Trim() method. This will remove any extra space before and after the string. Example is given. using System; namespace Hello_World { class Program { static void Main(string args) { string hello = " Hello World "; Console.WriteLine("Before: " + hello ); Console.WriteLine("After: " + hello.Trim());
To join strings in C#/CSharp, we make use of Concat method. Example is given below. using System; namespace Hello_World { class Program { static void Main(string args) { string hello = "Hello "; string world = " World!"; string final = string.Concat(hello, world); Console.WriteLine(final); } } }
To generate a GUID in C#/CSharp, we make use of GUID class. Example is given below. using System; namespace Hello_World { class Program { static void Main(string args) { Guid myGuid = Guid.NewGuid(); Console.WriteLine(myGuid.ToString()); } } } ;