Samual Sam has Published 2310 Articles

Orderby clause in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 13:45:07

472 Views

The orderby is used in C# to sort elements in the collection based on specified fields in a particular order. The order can be ascending or descending.The following is our list with elements −List myList = new List(); // adding elements myList.Add("iOS by Apple"); myList.Add("Android by Google"); myList.Add("Symbian by ... Read More

Append to StringBuilder in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 13:39:34

521 Views

The Append() method add content to a StringBuilder.Set a String −StringBuilder str = new StringBuilder();Now, loop through the number of elements you want and use Append () to append to StringBuilder −for (int j = 0; j < 5; j++) {    str.Append(j).Append(" "); }The following is the complete code ... Read More

How can we list all the columns of a MySQL view as we can list the columns of a MySQL table?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 13:38:47

290 Views

As we know that views are a type of virtual tables and are the composition of tables too hence we can use the same query to list all the columns of a MySQL view as we can list the columns of a MySQL table. In other words, we can use ... Read More

Replace a string using StringBuilder

Samual Sam

Samual Sam

Updated on 22-Jun-2020 13:38:40

755 Views

Set a String −StringBuilder str = new StringBuilder("Fitness is important");Use the Replace() method to replace a string −str.Replace("important", "essential");The following is the code to replace a string using StringBuilder −Example Live Demousing System; using System.Text; class Demo {    static void Main() {       // Initial String ... Read More

Iterating C# StringBuilder in a foreach loop

Samual Sam

Samual Sam

Updated on 22-Jun-2020 13:37:06

2K+ Views

Firstly, set a string array and StringBuilder −// string array string[] myStr = { "One", "Two", "Three", "Four" }; StringBuilder str = new StringBuilder("We will print now...").AppendLine();Now, use foreach loop to iterate −foreach (string item in myStr) {    str.Append(item).AppendLine(); }The following is the complete code −Example Live Demousing System; using ... Read More

Access a character in C# StringBuilder

Samual Sam

Samual Sam

Updated on 22-Jun-2020 13:35:57

418 Views

Firstly, set the StringBuilder −StringBuilder str = new StringBuilder(); str.Append("premium");To access the 5th character and display it −Console.WriteLine(str[4]);The following is the complete code −Example Live Demousing System; using System.Text; public class Demo {    public static void Main() {       StringBuilder str = new StringBuilder();       ... Read More

C# program to remove characters starting at a particular index in StringBuilder

Samual Sam

Samual Sam

Updated on 22-Jun-2020 13:35:12

127 Views

Set StringBuilder −StringBuilder str = new StringBuilder("Airport");Let’s say you need to remove characters. For that, use the Remove() method, which removes a bunch of characters beginning with a particular index −str.Remove(3, 4);The above removes four characters beginning from 3rd index (i.e. 4th position) −Here is the complete code −Example Live Demousing ... Read More

Scope of Variables in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 13:25:45

993 Views

The scope of a variable is a region of code that indicates where the variables are being accessed.For a variable, it has the following levels −Method LevelVariable declared inside a method is a local variable.Class LevelVariable declared inside a class is a local variable are class member variables.Let us see ... Read More

C# program to convert an array to an ordinary list with the same items

Samual Sam

Samual Sam

Updated on 22-Jun-2020 13:24:36

106 Views

Set an array −int[] arr = { 23, 66, 96, 110 };Now, create a new list −var list = new List();Use the Add method and add the array elements to the list −for (int i = 0; i < arr.Length; i++) {    list.Add(arr[i]); }The following is the complete code ... Read More

File Searching using C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 13:14:39

578 Views

To search files from the list of files in a directory, try to run the following code −Exampleusing System; using System.IO; namespace Demo {    class Program {       static void Main(string[] args) {          //creating a DirectoryInfo object          DirectoryInfo ... Read More

Advertisements