Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 2534 of 2650
14K+ Views
To declare and initialize a list in C#, firstly declare the list −List myList = new List()Now add elements −List myList = new List() { "one", "two", "three", };Through this, we added six elements above.The following is the complete code to declare and initialize a list in C# −Example Live Demousing System; using System.Collections.Generic; class Program { static void Main() { // Initializing collections List myList = new List() { "one", "two", "three", "four", "five", "size" }; Console.WriteLine(myList.Count); } }Output6
1K+ Views
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 −Example Live Demousing System; using System.Collections.Generic; public class Demo { public static void Main() { IDictionary d = new Dictionary(); d.Add(1, 97); ... Read More
391 Views
Events are user actions such as key press, clicks, mouse movements, etc., or some occurrence such as system-generated notifications.The events are declared and raised in a class and associated with the event handlers using delegates within the same class or some other class. The class containing the event is used to publish the event.To declare an event inside a class, first a delegate type for the event must be declared. For example, public delegate string myDelegate(string str);Now, declare an event −event myDelegate newEvent;Let us see an example to work with events in C# −Example Live Demousing System; namespace Demo { ... Read More
586 Views
The following is the first program in C# programming −Example Live Demousing 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 ... Read More
362 Views
Iterator performs a custom iteration over a collection. It uses the yield return statement and returns each element one at a time. The iterator remembers the current location and in the next iteration the next element is returned.The following is an example −Example Live Demousing System; using System.Collections.Generic; using System.Linq; namespace Demo { class Program { public static IEnumerable display() { int[] arr = new int[] {99, 45, 76}; foreach (var val in arr) { yield return val.ToString(); ... Read More
3K+ Views
In C#, you can use strings as an array of characters, However, more common practice is to use the string keyword to declare a string variable. The string keyword is an alias for the System.String class.To declare an empty string.string[] arr = new string[] {}; // empty stringNow let us see what will happen when we will print this empty string.Example Live Demousing System; namespace Demo { class Program { static void Main(string[] args) { string[] arr = new string[] {}; // empty string ... Read More
406 Views
When a method with parameters is called, you need to pass the parameters to the method using any of the following three methods -Reference ParametersThis method copies the reference to the memory location of an argument into the formal parameter. This means that changes made to the parameter affect the argument.Value ParametersThis method copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument.In Value parameters, when a method is called, a new storage location is created for each value ... Read More
2K+ Views
A destructor is a special member function of a class that is executed whenever an object of its class goes out of scope.It has exactly the same name as that of the class with a prefixed tilde (~), for example, our class name is Demo.public Demo() { // constructor Console.WriteLine("Object is being created"); } ~Demo() { //destructor Console.WriteLine("Object is being deleted"); }Let us see an example to learn how to work with Destructor in C#.Example Live Demousing System; namespace LineApplication { class Line { private double length; // Length of a line ... Read More
822 Views
Like any other programming language, in C#, you can easily create a user-defined exception. User-defined exception classes are derived from the Exception class. Custom exceptions are what we call user-defined exceptions.In the below example, the exception created is not a built-in exception; it is a custom exception −TempIsZeroExceptionYou can try to run the following code to learn how to create a user-defined exception in C#.Example Live Demousing System; namespace Demo { class TestTemperature { static void Main(string[] args) { Temperature temp = new Temperature(); try { ... Read More
352 Views
A delegate in C# is a reference to the method. A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime.Delegates are especially used for implementing events and the call-back methods. All delegates are implicitly derived from the System.Delegate class.Let us see how to declare delegates in C#.delegate Let us see an example to learn how to work with Delegates in C#.Example Live Demousing System; using System.IO; namespace DelegateAppl { class PrintString { static FileStream fs; static StreamWriter sw; ... Read More