Found 34494 Articles for Programming

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

Samual Sam
Updated on 21-Jun-2020 12:05:51

806 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 the hidden features of C#?

Chandu yadav
Updated on 21-Jun-2020 12:06:09

285 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 escape sequences supported by C#?

karthikeya Boyini
Updated on 21-Jun-2020 12:06:35

108 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 is Type safe in C#?

Samual Sam
Updated on 21-Jun-2020 12:13:47

1K+ Views

Type safe in C# wouldn’t allow an object to sneak into other object’s memory. Let us see an example to understand the concept of −Examplepublic class One {    public int Prop{ get; set;} } public class Two {    public int Prop{get;set;}    public int Prop1{get;set;} }Let’s say I have an object Class One −One ob = new One();Now you won’t be able to cast your object ob to the second class i.e. class Two. If you will cast it then a compile time error will arise because of the Type Safe feature in C#.

Transpose a matrix in C#

George John
Updated on 21-Jun-2020 12:11:32

2K+ Views

Transpose of a matrix flips the matrix over its diagonal and this brings the row elements on the column and column elements on the row.For example −Matrix before Transpose: 123 456 789 Matrix after Transpose: 147 258 369Let us see an example in C# to achieve transpose of a matrix −Exampleusing System; public class Demo {    public static void Main() {       int i, j, m, n;       int[, ] arr1 = new int[30, 30];       int[, ] arr2 = new int[30, 30];       Console.Write("Enter the number of ... Read More

What is the octal equivalent of a decimal number in C#?

karthikeya Boyini
Updated on 21-Jun-2020 12:14:46

121 Views

To get the octal equivalent of a decimal in C# −Firstly, for the decimal value use a while loop and store the remainder in the array set for octal. Here we found the mod 8 of them in the array.After that, divide the number by 8 −while (dec != 0) {    oct[i] = dec % 8;    dec = dec / 8;    i++; }Let us see the complete code. Here, our decimal number is 12 −Exampleusing System; namespace Demo {    class Program {       static void Main(string[] args) {       ... Read More

What are string and String data types in C#?

Arjun Thakur
Updated on 21-Jun-2020 11:53:45

530 Views

String stands for System.String whereas string is an alias in C# for System.String −For example −string str = "Welcome!";It’s not essential, but generally String is used when you work with classes −string str = String.Format("Welcome! {0}!", user);Since string is an alias for System.String. The alias for other datatypes are −EXampleobject: System.Object string: System.String bool: System.Boolean float: System.Single double: System.Double decimal: System.Decimal byte: System.Byte sbyte: System.SByte short: System.Int16 ushort: System.UInt16 int: System.Int32 uint: System.UInt32 long: System.Int64 ulong: System.UInt64 char: System.CharThe String type in C# allows you to assign any string values to a variable. The string type is an alias for ... Read More

What are static or fixed length arrays in C#?

Samual Sam
Updated on 21-Jun-2020 11:56:11

1K+ 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;       }    } }

What are sealed modifiers in C#?

Ankith Reddy
Updated on 21-Jun-2020 11:57:56

329 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 punctuators in C#?

karthikeya Boyini
Updated on 21-Jun-2020 11:58:22

350 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" };

Advertisements