Karthikeya Boyini has Published 2383 Articles

An array of streams in C#

karthikeya Boyini

karthikeya Boyini

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

523 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

356 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

157 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

2K+ 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

97 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

181 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

356 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

How to convert Lower case to Upper Case using C#?

karthikeya Boyini

karthikeya Boyini

Updated on 21-Jun-2020 12:53:47

2K+ Views

To convert Lower case to Upper case, use the ToUpper() method in C#.Let’s say your string is −str = "david";To convert the above lowercase string in uppercase, use the ToUpper() method −Console.WriteLine("Converted to UpperCase : {0}", str.ToUpper());The following is the code in C# to convert character case −Exampleusing System; using ... Read More

User-defined Exceptions in C# with Example

karthikeya Boyini

karthikeya Boyini

Updated on 21-Jun-2020 12:52:40

4K+ Views

An exception is a problem that arises during the execution of a program. A C# exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero.Define your own exception. User-defined exception classes are derived from the Exception class.The ... Read More

Advertisements