Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by karthikeya Boyini
Page 41 of 143
C# program to merge two sorted arrays into one
Set two arrays that you wish to merge −int[] arr1 = new int[5] { 5, 15, 25, 30, 47 }; int[] arr2 = new int[5] { 55, 60, 76, 83, 95 };Now take a third array that would merge both the above arrays −int[] merged = new int[10];The following is the code that merges two arrays into the third array in C# −Exampleusing System; using System.Collections.Generic; class Program { static void Main() { int i = 0; int j = 0; ...
Read MoreShow Bootstrap class
To show a Bootstrap class, use the .show class. You can try to run the following code to make a class visibleExample Bootstrap Example This class is visible. This is an example for hide class. This will be hidden.
Read MoreClear a list in C#
Firstly, set a list −List myList = new List(); myList.Add(45); myList.Add(77);Now, to clear the above list, use Clear() −myList.Clear();Here is the complete code −Exampleusing System; using System.Collections.Generic; public class Demo { public static void Main() { List myList = new List(); myList.Add(45); myList.Add(77); Console.WriteLine("Elements: "+myList.Count); myList.Clear(); Console.WriteLine("Elements after using clear: "+myList.Count); } }OutputElements: 2 Elements after using clear: 0
Read MoreHow to write the first program in C#?
The following is the first program in C# programming −Exampleusing System; namespace MyHelloWorldApplication { class MyDemoClass { static void Main(string[] args) { // display text Console.WriteLine("Hello World"); // display another text Console.WriteLine("Welcome!"); Console.ReadKey(); } } }OutputHello World Welcome!Let us see now what all it includes.using System; - the using keyword is used to include the System namespace in the program.namespace declaration - A namespace is a collection ...
Read MoreFlow control in try catch finally in C#
The flow control in try, catch, and finally can be understood using the following example. Here, we are dividing two numbers −Exampleusing System; namespace ErrorHandlingApplication { class DivNumbers { int result; DivNumbers() { result = 0; } public void division(int num1, int num2) { try { result = num1 / num2; } catch (DivideByZeroException e) { Console.WriteLine("Exception caught: {0}", e); ...
Read MoreC# program to find the index of an element in a List
Set a list and add elements −List val = new List(); // integer elements val.Add(35); val.Add(55); val.Add(68);Let’s say now we need to find the index of element 68. For that, use the IndexOf() method −int index = val.IndexOf(68);Here is the complete code −Exampleusing System; using System.Collections.Generic; public class Demo { public static void Main() { List val = new List(); // integer elements val.Add(35); val.Add(55); val.Add(68); // finding the index of element 68 int index = val.IndexOf(68); Console.WriteLine(index); } }Output2
Read MoreHow to declare and initialize a dictionary in C#?
Dictionary is a collection of keys and values in C#. Dictionary is included in the System.Collection.Generics namespace.To declare and initialize a Dictionary −IDictionary d = new Dictionary();Above, types of key and value are set while declaring a dictionary object. An int is a type of key and string is a type of value. Both will get stored in a dictionary object named d.Let us now see an example −Exampleusing System; using System.Collections.Generic; public class Demo { public static void Main() { IDictionary d = new Dictionary(); d.Add(1, 97); d.Add(2, ...
Read MoreC# Program to find the smallest element from an array using Lambda Expressions
Declare an array −int[] arr = { 10, 15, 5, 20};Now to get the smallest element from an array, use Min() method with lambda expressions −arr.Min());Here is the complete code −Exampleusing System; using System.Linq; class Demo { static void Main() { int[] arr = { 10, 15, 5, 20}; Console.WriteLine(arr.Min(element => Math.Abs(element))); } }Output5
Read MoreAccess Modifiers in C#
Access Modifiers specifies the scope of variable and functions in C#. The following are the access modifiers used provided by C#:PublicThe public modifier sets no restriction on the access of members.ProtectedAccess limited to the derived class or class definition.InternalThe Internal access modifier access within the program that has its declaration.Protected internalIt has both the access specifiers provided by protected and internal access modifiers.PrivateLimited only inside the class in which it is declared. The members specified as private cannot be accessed outside the class.ExampleLet us see an example of protected access modifier, accessing the protected members −using System; namespace MySpecifiers { ...
Read MoreC# program to get the List of keys from a Dictionary
Set the dictionary elements −Dictionary d = new Dictionary(); // dictionary elements d.Add(1, "One"); d.Add(2, "Two"); d.Add(3, "Three"); d.Add(4, "Four"); d.Add(5, "Five"); d.Add(6, "Six"); d.Add(7, "Seven"); d.Add(8, "Eight");To get the keys, use a list collection −List keys = new List(d.Keys);Loop through the keys and display them.Here is the complete code −Exampleusing System; using System.Collections.Generic; public class Demo { public static void Main() { Dictionary d = new Dictionary(); // dictionary elements d.Add(1, "One"); d.Add(2, "Two"); d.Add(3, "Three"); d.Add(4, "Four"); ...
Read More