Chandu yadav has Published 1163 Articles

GetLogicalDrives in C#

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 15:02:11

168 Views

To get all the disk drives on a system, use the GetLogicalDrives() method in C# −Environment.GetLogicalDrives()Use it with Join method to get the comma-separated list of logical drives −string.Join(", ", Environment.GetLogicalDrives())Example Live Demousing System; using System.IO; namespace Demo {    class Program {       static void Main(string[] args) { ... Read More

C# Program to remove the end part of a string

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 14:53:18

439 Views

Use the Regex.Replace method to remove the end part of a string in C#.The following is the string −string s1 = "Demo Text!";Now, let us say you need to remove the exclamation mark (!) from the string. For that just set it to empty using replace −System.Text.RegularExpressions.Regex.Replace(s1, "!", "");Here is ... Read More

C# Program to split a string on spaces

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 14:46:25

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 ... Read More

Set 6-item tuple in C#’

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 14:44:48

66 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; ... Read More

How we have multiple stored GENERATED COLUMNS in MySQL table with CREATE TABLE statement?

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 14:36:03

93 Views

It is quite possible to add multiple stored generated columns in a MySQL table. It can be illustrated with the following example as follows −Examplemysql> Create table profit1(cost int, price int, profit int AS (price-cost) STORED, price_revised int AS (price-2) STORED); Query OK, 0 rows affected (0.36 sec) mysql> ... Read More

All Method in C#

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 14:30:29

238 Views

The All() extension method is part of the System.Linq namepspace. Using this method, you can check whether all the elements match a certain condition or not.Set an array −int[] arr = { 6, 7, 15, 40, 55 };The following is an example. It checks whether all the elements in the ... Read More

KeyNotFoundException in C#

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 14:27:28

437 Views

The KeyNotFoundException is thrown when a key you are finding is not available in the Dictionary collection.Let us see an example −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main() {       try {          var dict = new Dictionary() ... Read More

C# Program to display the last three elements from a list in reverse order

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 14:19:58

1K+ Views

To display the last three elements from a list, use the Take() method. For reversing it, use the Reverse() method.Firstly, declare a list and add elements to it −List myList = new List(); myList.Add("One"); myList.Add("Two"); myList.Add("Three"); myList.Add("Four");Now, use the Take() method with Reverse() to display the last three elements from ... Read More

Display years in different formats with C# DateTime

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 14:18:09

99 Views

Set a DateTime object;DateTime dt = DateTime.Now;To get years in different formats, try the following −dt.ToString("yy") dt.ToString("yyy") dt.ToString("yyyy") dt.ToString("yyyyy")Here is the complete code −Example Live Demousing System; using System.Threading; using System.Diagnostics; public class Demo {    public static void Main() {       DateTime dt = DateTime.Now;       ... Read More

C# program to convert string to long

Chandu yadav

Chandu yadav

Updated on 22-Jun-2020 14:15:30

12K+ Views

To convert a string to a long, use the Long.parse method in C# −Firstly, set a string −string str = "6987646475767";Now, convert it to long −long.Parse(str);Here is the complete code −Example Live Demousing System; using System.Linq; class Demo {    static void Main() {       string str = "6987646475767"; ... Read More

Advertisements