Found 2628 Articles for Csharp

What are the escape sequences supported by C#?

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

105 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

525 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

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

What are extender provider components in C#?

George John
Updated on 21-Jun-2020 11:58:57

114 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.

What are multicasting delegates in C#?

Samual Sam
Updated on 20-Jun-2020 17:30:17

1K+ Views

A delegate that holds a reference to more than one method is called multicasting delegate.Let us see an example −Exampleusing System; delegate void myDelegate(int val1, int val2); public class Demo {    public static void CalAdd(int val1, int val2) {       Console.WriteLine("{0} + {1} = {2}", val1, val2, val1 + val2);    }    public static void CalSub(int val1, int val2) {       Console.WriteLine("{0} - {1} = {2}", val1, val2, val1 - val2);    } } public class Program {    static void Main() {       myDelegate d = new myDelegate(Demo.CalAdd);   ... Read More

Advertisements