Samual Sam has Published 2492 Articles

C# program to create a List with elements from an array

Samual Sam

Samual Sam

Updated on 22-Jun-2020 13:58:10

324 Views

Set an array −int[] val = new int[5]; // integer elements val[0] = 15; val[1] = 25; val[2] = 40; val[3] = 58; val[4] = 70;Now set a list and add array in it −List myList = new List(val);The following is the code −Example Live Demousing System; using System.Collections.Generic; public ... Read More

Declare char arrays in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 13:46:46

5K+ Views

Declare a char array and set the size −char[] arr = new char[5];Now set the elements −arr[0] = 'h'; arr[1] = 'a'; arr[2] = 'n'; arr[3] = 'k'; arr[4] = 's';Let us see the complete code now to declare, initialize and display char arrays in C# −Example Live Demousing System; ... Read More

Orderby clause in C#

Samual Sam

Samual Sam

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

383 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

414 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

224 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

526 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

313 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

72 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

701 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

Advertisements