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
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
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.
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" };
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
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; } } }
To set the color of the four borders, use the border-color property. You can try to run the following code to set border color for all the bordersExampleLive Demo p { border-style: dashed; border-color: #808000 #800000 #FF0000 #FFFF00; } This is demo text with four colored border. Output
To set the width of the left border, use the border-left-width property in CSS. You can try to run the following code to implement the border-left-width property −ExampleLive Demo p { border-style: dashed; border-left-width: 10px; } This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is ... Read More
To set the style of the bottom border, use the border-bottom-style property. The values for the border you can set is, dotted, double, dashed, solid, etc.ExampleYou can try to run the following code to style bottom borderLive Demo p.dotted {border-bottom-style: dotted;} p.double {border-bottom-style: double;} p.dashed {border-bottom-style: dashed;} p.solid {border-bottom-style: solid;} p.inset {border-bottom-style: inset;} p.outset {border-bottom-style: outset;} Dotted bottom border. Double bottom border. Dashed bottom border. Solid bottom border. Inset bottom border. Outset bottom border. Output
Use the CSS :nth-last-of-type(n) selector to select every element that is the second element of its parent, counting from the last child.ExampleYou can try to run the following code to implement the :nth-last-of-type(n) selector:Live Demo p:nth-last-of-type(2) { background: blue; color: white; } This is demo text 1. This is demo text 2. This is demo text 3. This is demo text 4. This is demo text 5.
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP