Server Side Programming Articles - Page 2505 of 2650

How to add string values to a C# list?

karthikeya Boyini
Updated on 21-Jun-2020 14:51:06

17K+ Views

To add string values to a list in C#, use the Add() method.Firstly, declare a string list in C# −List list1 = new List();Now add string items −myList.Add("Jack"); myList.Add("Ben"); myList.Add("Eon"); myList.Add("Tim");Let us see the complete code −Exampleusing System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Demo {    public class Program {       public static void Main(String[] args) {          List myList = new List();          myList.Add("Jack");          myList.Add("Ben");          myList.Add("Eon");          myList.Add("Tim");          Console.WriteLine(myList.Count);       }    } }

How to add items/elements to an existing jagged array in C#?

Ankith Reddy
Updated on 21-Jun-2020 14:50:24

913 Views

To add an element to existing jagged array, just set the value of the element with a new value.Let’s say you need to add an element at the following location −a[3][1]Just set the value −a[3][1] = 500;Above, we accessed the first element of the 3rd array in a jagged array.Let us see the complete code −Exampleusing System; namespace Demo {    class Program {       static void Main(string[] args) {          int[][] x = new int[][]{new int[]{10, 20}, new int[]{30, 40}, new int[]{50, 60}, new int[]{ 70, 80 }, new int[]{ 90, 100 ... Read More

How to add integer values to a C# list?

Samual Sam
Updated on 21-Jun-2020 14:58:47

9K+ Views

To add integer values to a list in C#, use the Add() method.Firstly, declare an integer list in C# −List list1 = new List();Now add integer values −list1.Add(900); list1.Add(400); list1.Add(300);Let us see the complete code −Exampleusing System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Demo {    public class Program {       public static void Main(String[] args) {          List list1 = new List();          list1.Add(900);          list1.Add(400);          list1.Add(300);          Console.WriteLine(list1.Count);       }    } }

How to add items to a list in C#?

Arjun Thakur
Updated on 21-Jun-2020 14:58:17

938 Views

Firstly, declare a list −var teams = new List();To add items to a C# list, use the Add() method −teams.Add("US"); teams.Add("Canada"); teams.Add("India"); teams.Add("Australia");You can try to run the following code to add items to a list in C# −Exampleusing System; using System.Collections.Generic; public class Demo {    public static void Main(string[] args) {       var teams = new List();       teams.Add("US");       teams.Add("Canada");       teams.Add("India");       teams.Add("Australia");           Console.WriteLine("Elements...");       foreach (var countries in teams) {          Console.WriteLine(countries);       }    } }

Find all substrings in a string using C#

karthikeya Boyini
Updated on 21-Jun-2020 14:25:18

533 Views

Use the substring() method in C# to find all substrings in a string.Let’s say our string is −pqrLoop through the length of the string and use the Substring function from the beginning to the end of the string −for (int start = 0; start

File Handling in C#

George John
Updated on 21-Jun-2020 14:34:14

837 Views

A file is a collection of data stored in a disk with a specific name and a directory path. When a file is opened for reading or writing, it becomes a stream.In C#, you need to create a FileStream object to create a new file or open an existing file. The syntax for creating a FileStream object is as follows −FileStream = new FileStream( , , , );Here, the file operations are also included as shown below −The FileMode enumerator defines various methods for opening files. The members of the FileMode enumerator are −Append − It opens an existing ... Read More

What is the System.Reflection.Module in C#?

Chandu yadav
Updated on 21-Jun-2020 14:18:33

248 Views

The System.Reflection namespace contains classes that allow you to obtain information about the application and to dynamically add types, values, and objects to the application.It has a module constructor that initializes a new instance of the Module class. A module is a portable executable file that has one or more classes and interfaces.Let us see an example of System.Reflection in C# −Exampleusing System; using System.Reflection; [AttributeUsage(AttributeTargets.All)] public class HelpAttribute : System.Attribute {    public readonly string Url;    public string Topic // Topic is a named parameter {       get {          return ... Read More

How to define character constants in C#?

Chandu yadav
Updated on 21-Jun-2020 13:50:27

282 Views

Character literals are enclosed in single quotes. For example, 'x' and can be stored in a simple variable of char type. A character literal can be a plain character (such as 'x'), an escape sequence (such as '\t'), or a universal character (such as '\u02C0').Let us see an example how to define a character constant in C# −using System; namespace Demo {    class Program {       static void Main(string[] args) {          Console.WriteLine("Welcome!\t");          Console.WriteLine("This is it!");          Console.ReadLine();       }    } }Above, we ... Read More

Variable Arguments (Varargs) in C#

Arjun Thakur
Updated on 21-Jun-2020 13:59:58

6K+ Views

Use the param keyword to get the variable arguments in C#.Let us see an example to multiply integers. We have used params keyword to accept any number of int values −static int Multiply(params int[] b)The above allows us to find multiplication of numbers with one as well as two int values. The fllowing calls the same function with multiple values −int mulVal1 = Multiply(5); int mulVal2 = Multiply(5, 10);Let us see the complete code to understand how variable arguments work in C# −Exampleusing System; class Program {    static void Main() {       int mulVal1 = Multiply(5); ... Read More

How to create a Directory using C#?

Samual Sam
Updated on 21-Jun-2020 14:00:14

437 Views

To create, move and delete directories in C#, the System.IO.Directory class has methods.Firstly, import the System.IO namespace.Now, use the Director.CreateDirectory() method to create a directory in the specified path −string myDir = @"D:\NEW"; if (!Directory.Exists(myDir)) {    Directory.CreateDirectory(myDir); }In the same way, you can create a sub-directory −string mysubdir = @"C:\NEW\my\"; Directory.CreateDirectory(mysubdir);

Advertisements