Csharp Articles

Page 157 of 196

What are the escape sequences supported by C#?

karthikeya Boyini
karthikeya Boyini
Updated on 21-Jun-2020 220 Views

The following is an example showing how to display some of the escape characters in C# −Exampleusing System; using System.Collections.Generic; class Demo {    static void Main() {       Console.WriteLine("Warning!" + '\u0007');       Console.WriteLine("Test \t Demo Text");       Console.WriteLine("This is it!This is on the next line!");    } }For the complete list of escape sequences in C# −Escape characterDescriptionPattern\aMatches a bell character, \u0007.\a\bIn a character class, matches a backspace, \u0008.[\b]{3, }\tMatches a tab, \u0009.(\w+)\t\rMatches a carriage return, \u000D. (\r is not equivalent to the newline character, .)\r(\w+)\vMatches a vertical tab, ...

Read More

What are the hidden features of C#?

Chandu yadav
Chandu yadav
Updated on 21-Jun-2020 440 Views

The following are the hidden or lesser known useful features of C# −Lambda ExpressionsA lambda expression in C# describes a pattern. It has the token => in an expression context. This is called goes to operator and used when a lambda expression is declared.NullablesC# provides a special data types, the nullable types, to which you can assign normal range of values as well as null values. The following is the syntax − ? = null;Null Coalescing OperatorThe null coalescing operator is used with the nullable value types and reference types. It is used for converting an operand to the ...

Read More

What are the interfaces implemented by Array class in C#?

Samual Sam
Samual Sam
Updated on 21-Jun-2020 1K+ Views

System.Array implements interfaces, like ICloneable, IList, ICollection, and IEnumerable, etc. The ICloneable interface creates a copy of the existing object i.e a clone.Let us see learn about the ICloneable interface. It only has a Clone() methods because it creates a new object that is a copy of the current instance.The following is an example showing how to perform cloning using ICloneable interface −Exampleusing System; class Car : ICloneable {    int width;    public Car(int width) {       this.width = width;    }    public object Clone() {       return new Car(this.width);   ...

Read More

What are extender provider components in C#?

George John
George John
Updated on 21-Jun-2020 240 Views

To provide properties to other components, the extender provider is used. Let’s consider an example of a TooTtip component.You add the component to a form. This sets a ToolTip property to every control. The same property is not under the attacked PropertyGrid control.myTooltip1.SetToolTip(btn1, "This is ToolTip!");Let us see how to implement extender provider component −Firstly, define a component −public class MyExtender : IExtenderProvider {...}IExtenderProvider definition −public interface IExtenderProvider {    bool newExtend(object extendeNew); }Now you need to implement the newExtend method. This is done to return true for every related component or control.

Read More

What are punctuators in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 21-Jun-2020 691 Views

Punctuators are used in C# as special symbols to a group or divide the code. It includes −] () {}, ; * = #For example, = gets included in a class or even while declaring a variable. Statement ends with a semi-colon −int a = 10;In a class, the braces are used −class Demo { }While declaring a dictionary −var d = new Dictionary(5);It is also used while declaring and initializing a list −List myList = new List() {    "mammals",    "reptiles",    "amphibians" };

Read More

What are sealed modifiers in C#?

Ankith Reddy
Ankith Reddy
Updated on 21-Jun-2020 528 Views

When you use sealed modifiers in C# on a method, then the method loses its capabilities of overriding. The sealed method should be part of a derived class and the method must be an overridden method.Let us see an example −The following example won’t allow you to override the method display() because it has a sealed modifier for the ClassTwo derived class −ClassOne is our base class, whereas ClassTwo and ClassThree are derived classes −Exampleclass ClassOne {    public virtual void display() {       Console.WriteLine("baseclass");    } } class ClassTwo : ClassOne {    public sealed override ...

Read More

What are static or fixed length arrays in C#?

Samual Sam
Samual Sam
Updated on 21-Jun-2020 2K+ Views

A static array is a data structure with a fixed size. Let us see an example of a static array in C#.Here is a static string array. The data remains the same here i.e. fixed −static string[] _fruits = new string[] {    "apple",    "mango" };Now let us see the complete example to create and access static arrays in C# −Exampleusing System; class Demo {    static void Main() {       foreach (string fruits in Program.Fruits) {          Console.WriteLine(fruits);       }    } } public static class Program {    static string[] _fruits = new string[] {       "apple",       "mango"    };    public static string[] Fruits {       get {          return _fruits;       }    } }

Read More

What is a dictionary in C#?

Samual Sam
Samual Sam
Updated on 20-Jun-2020 3K+ 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 −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 More

What is the best way to iterate over a Dictionary in C#?

Samual Sam
Samual Sam
Updated on 20-Jun-2020 2K+ Views

In a Dictionary collection, store any data type. Dictionary is a collection of keys and values in C#. Dictionary is included in the System.Collection.Generics namespace.Let us now see the best way to iterate over a Dictionary in C# −Firstly, let us create a dictionary −var d = new Dictionary(5);Now add the key and value −// add key and value d.Add("car", 25); d.Add("bus", 28); d.Add("motorbike", 17);Use orderby to order by values −var val = from ele in d orderby ele.Value ascending select ele;We have set ascending above to sort the dictionary in ascending order. You can also use descending.Display the values ...

Read More

Thread Pools in C#

karthikeya Boyini
karthikeya Boyini
Updated on 20-Jun-2020 4K+ Views

Thread pool in C# is a collection of threads. It is used to perform tasks in the background. When a thread completes a task, it is sent to the queue wherein all the waiting threads are present. This is done so that it can be reused.Let us see how to create a thread pool.Firstly, use the following namespace −using System.Threading;Now, call the threadpool class, using the threadpool object. Call the method QueueUserWorkItem −ThreadPool.QueueUserWorkItem(new WaitCallback(Run)); Iterate this in a loop and compare it with a normal Thread object.

Read More
Showing 1561–1570 of 1,951 articles
« Prev 1 155 156 157 158 159 196 Next »
Advertisements