Karthikeya Boyini has Published 2193 Articles

What is index-based I/O ArrayList collection in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 21-Jun-2020 14:59:39

469 Views

ArrayList class represents an ordered collection of an object that can be indexed individually. It is an alternative to an array.The following table lists some of the commonly used properties of the ArrayList class −Sr.NoProperty & Description1CapacityGets or sets the number of elements that the ArrayList can contain.2CountGets the number ... Read More

How to add string values to a C# list?

karthikeya Boyini

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

An array of streams in C#

karthikeya Boyini

karthikeya Boyini

Updated on 21-Jun-2020 14:44:13

765 Views

Set the string array for the values −string[] names = new string[] {"Jack", "Tom"};Now using foreach array, write the content in the file −using (StreamWriter sw = new StreamWriter("names.txt")) {    foreach (string s in names) {       sw.WriteLine(s);    } }The following is an example showing ... Read More

Find all substrings in a string using C#

karthikeya Boyini

karthikeya Boyini

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

521 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

How to create a Dictionary using C#?

karthikeya Boyini

karthikeya Boyini

Updated on 21-Jun-2020 14:02:04

230 Views

Dictionary is a collection of keys and values in C#. Dictionary is included in the System.Collection.Generics namespace.To create a dictionary, you first need to set it and add the key and values. Here we have added 5 keys with values to a Dictionary. We have set its keys and value ... Read More

How to convert a 2D array into 1D array in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 21-Jun-2020 13:42:39

3K+ Views

Set a two-dimensional array and a one-dimensional array −int[, ] a = new int[2, 2] {{1, 2}, {3, 4} }; int[] b = new int[4];To convert 2D to 1D array, set the two dimensional into one-dimensional we declared before −for (i = 0; i < 2; i++) {    for ... Read More

How are parameters passed in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 21-Jun-2020 13:29:06

200 Views

Parameters are passed in C# either by value or by reference. With that, you can also use out parameters and param array to pass parameters −ValueThis method copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside ... Read More

How to compare two dictionaries in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 21-Jun-2020 13:18:26

3K+ Views

To compare two dictionaries, firstly set the two dictionaries −Dictionary OneIDictionary d = new Dictionary(); d.Add(1, 97); d.Add(2, 89); d.Add(3, 77); d.Add(4, 88); // Dictionary One elements Console.WriteLine("Dictionary One elements: "+d.Count);Dictionary OneIDictionary d2 = new Dictionary(); d2.Add(1, 97); d2.Add(2, 89); d2.Add(3, 77); d2.Add(4, 88); // Dictionary Two elements ... Read More

How to access elements from a rectangular array in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 21-Jun-2020 13:11:30

291 Views

To access elements from a rectangular array, you just need to set the index of which you want to get the element. Multi-dimensional arrays are also called rectangular array −a[0, 1]; // second elementThe following is an example showing how to work with a rectangular array in C# and access ... Read More

User-defined Custom Exception in C#

karthikeya Boyini

karthikeya Boyini

Updated on 21-Jun-2020 13:00:44

462 Views

C# exceptions are represented by classes. The exception classes in C# are mainly directly or indirectly derived from the System.Exception class.You can also define your own exception. User-defined exception classes are derived from the Exception class.The following is an example −Exampleusing System; namespace UserDefinedException {    class TestTemperature { ... Read More

Advertisements