Csharp Articles

Page 65 of 196

C# Program to display a string in reverse alphabetic order

Arjun Thakur
Arjun Thakur
Updated on 22-Jun-2020 878 Views

Set a string array and convert it to character array −string str = "Amit"; char[] arr = str.ToCharArray();Now, use the Reverse method to display the above string in reverse alphabetic order −Array.Reverse(arr);Here is the complete code −Example Live Demousing System; using System.Linq; using System.IO; class Program {    static void Main() {       string str = "Amit";       char[] arr = str.ToCharArray();       Console.WriteLine("Original String: "+str);       // Reverse       Array.Reverse(arr);       Console.WriteLine("Reversed String: "+new string(arr));    } }OutputOriginal String: Amit Reversed String: timA

Read More

C# Program to split a string on spaces

Chandu yadav
Chandu yadav
Updated on 22-Jun-2020 2K+ Views

Firstly, set a string −string str = "Science and Mathematics";Now use the Split() method to split wherever the spaces occur −str.Split(' ')The following is the complete code −Example Live Demousing System; using System.Linq; using System.IO; class Program {    static void Main() {       string str = "Science and Mathematics";       Console.WriteLine("String..."+str);       string[] myStr = str.Split(' ');       Console.WriteLine("Splitted String...");       foreach (string ch in myStr) {          Console.WriteLine(ch);       }    } }OutputString... Science and Mathematics Splitted String... Science and Mathematics

Read More

C# Program to split parts in a Windows directory

Arjun Thakur
Arjun Thakur
Updated on 22-Jun-2020 835 Views

Firstly, set a string i.e. your Windows directory path −string str = @"D:\Downloads\Amit";Now use the Split() method and split wherever the \ occur −str.Split(' \')The following is the complete code −Example Live Demousing System; class Program {    static void Main() {       string str = @"D:\Downloads\Amit";       Console.WriteLine("Directory..."+str);       string[] myStr = str.Split('\');       Console.WriteLine("Split...");       foreach (string ch in myStr) {          Console.WriteLine(ch);       }    } }OutputDirectory... D:\Downloads\Amit Split... D: Downloads Amit

Read More

C# Program to write a number in hexadecimal format

Ankith Reddy
Ankith Reddy
Updated on 22-Jun-2020 607 Views

Let’s say the following is the number −int a = 12250;You can work around the following ways to get a number in hexadecimal format −{0:x} {0:x8} {0:X} {0:X8}Here is the code −Example Live Demousing System; class Demo {    static void Main() {       int a = 12250;       Console.WriteLine("{0:x}", a);       Console.WriteLine("{0:x8}", a);       Console.WriteLine("{0:X}", a);       Console.WriteLine("{0:X8}", a);    } }Output2fda 00002fda 2FDA 00002FDA

Read More

Tuple.Create method in C#

George John
George John
Updated on 22-Jun-2020 141 Views

To create a tuple, use the Tuple.Create method.Here we have set a tuple with a string and int −var myTuple = Tuple.Create("marks", 100);The following is an example that creates a tuple using Tuple.Create and displays the elements in a single line in C# −Example Live Demousing System; class Demo {    static void Main() {       var myTuple = Tuple.Create("marks", 100);       Console.WriteLine(myTuple);    } }Output(marks, 100)

Read More

Set 6-item tuple in C#’

Chandu yadav
Chandu yadav
Updated on 22-Jun-2020 130 Views

With C#, you can easily set a 6-item tuple.The following is a 6-item tuple −var myTuple = new Tuple("electronics", new string[] { "shoes", "clothing#", "accessories" }, 100, 250, 500, 1000);above, we have tuple for string, string array and int as shown below −TupleHere is the complete code −Example Live Demousing System; class Demo {    static void Main() {       var myTuple = new Tuple("electronics",       new string[] { "shoes", "clothing#", "accessories" },       100,       250,       500,       1000);       // Displaying Item 1       Console.WriteLine(myTuple.Item1);       // Displaying Item 5       Console.WriteLine(myTuple.Item5);       // Displaying Item 6       Console.WriteLine(myTuple.Item6);    } }Outputelectronics 500 1000

Read More

C# Program to get the last write time of a file

karthikeya Boyini
karthikeya Boyini
Updated on 22-Jun-2020 2K+ Views

To get the last write time of a file in C#, use the LastWriteTime() method.For this, use the FileInfo as well as DateTime classes.Create an object of each −FileInfo file = new FileInfo("amit.txt"); DateTime dt = file.CreationTime; dt = file.LastWriteTime;Let us see the complete code −Example Live Demousing System.IO; using System; public class Program {    public static void Main() {       using (StreamWriter sw = new StreamWriter("amit.txt")) {          sw.WriteLine("Welcome!");       }       FileInfo file = new FileInfo("amit.txt");       // file creation time       DateTime dt = ...

Read More

C# Program to get the last access time of a file

Samual Sam
Samual Sam
Updated on 22-Jun-2020 825 Views

To get the last access time of a file in C#, use the LastAccessTime() method.For this, use the FileInfo as well as DateTime classes.Create an object of each −FileInfo file = new FileInfo("new.txt"); DateTime dt = file.CreationTime; dt = file.LastAccessTime;Let us see the complete code −Example Live Demousing System.IO; using System; public class Program {    public static void Main() {       using (StreamWriter sw = new StreamWriter("quiz.txt")) {          sw.WriteLine("Quizzes!");       }       FileInfo file = new FileInfo("quiz.txt");       // last access time       DateTime dt = file.LastAccessTime;       Console.WriteLine(dt);    } }Output9/5/2018 5:21:43 AM

Read More

Get the creation time of a file in C#

karthikeya Boyini
karthikeya Boyini
Updated on 22-Jun-2020 2K+ Views

To get the creation time of a file in C#, use the CreationTime() method.For this, use the FileInfo as well as DateTime classes.Create an object of each −FileInfo file = new FileInfo("new.txt"); DateTime dt = file.CreationTime;Let us see the complete code −Example Live Demousing System.IO; using System; public class Program {    public static void Main() {       using (StreamWriter sw = new StreamWriter("qa.txt")) {          sw.WriteLine("Questions and Answers!");       }       FileInfo file = new FileInfo("qa.txt");       // file creation time       DateTime dt = file.CreationTime;       Console.WriteLine(dt);    } }Output9/5/2018 5:20:03 AM

Read More

Lowercase suffixes in C#

Samual Sam
Samual Sam
Updated on 22-Jun-2020 184 Views

Set lowercase suffixes for literals such as u, l, ul, f, etc.// l for long long a = 29876l;It can be used on literal numbers as well. It tells the compiler that the literal is of a specific type.The following is an example −Example Live Demousing System.IO; using System; public class Program {    public static void Main() {       long a = 29876l;       float b = 95.10f;       Console.WriteLine(a);       Console.WriteLine(b);    } }On running the above example, you will get the following output. With that, you will also get a ...

Read More
Showing 641–650 of 1,951 articles
« Prev 1 63 64 65 66 67 196 Next »
Advertisements