Found 27759 Articles for Server Side Programming

What are the attributes in C#?

Samual Sam
Updated on 30-Jul-2019 22:30:23

141 Views

An attribute is a declarative tag that is used to convey information to runtime about the behaviours of various elements like classes, methods, structures, enumerators, assemblies etc. in your program. The following is the syntax. [attribute(positional_parameters, name_parameter = value, ...)] Element Here, Name of the attribute and its values are specified within the square brackets, before the element to which the attribute is applied. Positional parameters specify the essential information and the name parameters specify the optional information. The following are the predefined attributes in C#. AttributeUsage The pre-defined attribute AttributeUsage describes how a custom attribute class ... Read More

What are arithmetic operators in C#?

George John
Updated on 15-Apr-2020 12:28:48

170 Views

An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.OperatorDescriptionExample+Adds two operandsA + B = 30-Subtracts second operand from the firstA - B = -10*Multiplies both operandsA * B = 200/Divides numerator by de-numeratorB / A = 2%Modulus Operator and remainder of after an integer divisionB % A = 0++Increment operator increases integer value by oneA++ = 11--Decrement operator decreases integer value by oneA-- = 9Let us see an example to use arithmetic operators in C#.Example Live Demousing System; namespace Demo {    class Program {       static void Main(string[] args) {   ... Read More

What are anonymous methods in C#?

karthikeya Boyini
Updated on 23-Jun-2020 12:31:34

88 Views

Anonymous methods are the methods without a name. These methods provide a technique to pass a code block as a delegate parameter.Anonymous methods are declared with the creation of the delegate instance, with a delegate keyword.Example Live Demousing System; delegate void Demo(int n); namespace DelegateAppl {    class TestDelegate {       static int num = 50;       public static void AddNum(int p) {          num += p;          Console.WriteLine("Named Method: {0}", num);       }       public static void MultNum(int q) {          num *= ... Read More

What are anchors in regular expressions in C#?

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

184 Views

Anchors are constructs in regular expressions in C#. It allows a match to succeed or fail depending on the current position in the string. The following table lists the anchors. Assertion Description Pattern Matches ^ The match must start at the beginning of the string or line ^\d{3} "567" in "567-777-" $ The match must occur at the end of the string or before at the end of the line or string. -\d{4}$ "-2012" in "8-12-2012" \A The match must occur at the start of the string. \A\w{3} "Code" in "Code-007-" ... Read More

How to sort an ArrayList in C#?

Samual Sam
Updated on 23-Jun-2020 12:32:40

2K+ Views

To sort an ArrayList in C#, use the Sort() method.The following is the ArrayList.ArrayList arr = new ArrayList(); arr.Add(32); arr.Add(12); arr.Add(55); arr.Add(8); arr.Add(13);Now the Sort() method is used to sort the ArrayList.arr.Sort();You can try to run the following code to sort an ArrayList in C#.Example Live Demousing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {          ArrayList arr = new ArrayList();          arr.Add(32);          arr.Add(12);          arr.Add(55);          arr.Add(8);          arr.Add(13);     ... Read More

What are all the possible C# array initialization syntaxes?

Arjun Thakur
Updated on 23-Jun-2020 12:16:46

73 Views

Array can be initialized in more than one ways in C#. Let us see some example.Method OneUsing size of array.int [] marks = new int[5] { 99, 98, 92, 97, 95};Method TwoBy omitting the size.int [] marks = new int[] { 99, 98, 92, 97, 95};Method ThreeInitializing at the time of declaration.int [] marks = { 99, 98, 92, 97, 95};Let us see one of the ways to initialize arrays in C#.Example Live Demousing System; namespace Demo {    class MyArray {       static void Main(string[] args) {          int [] n = new int[10]; /* ... Read More

What are Add, Remove methods in C# lists?

karthikeya Boyini
Updated on 23-Jun-2020 12:17:39

630 Views

The List is a collection in C# and is a generic collection. The add and remove methods are used in C# lists for adding and removing elements.Let us see how to use Add() method in C#.Example Live Demousing System; using System.Collections.Generic; class Program {    static void Main() {       List sports = new List();       sports.Add("Football");       sports.Add("Tennis");       sports.Add("Soccer");       foreach (string s in sports) {          Console.WriteLine(s);       }    } }OutputFootball Tennis SoccerLet us see how to use Remove() method in C#.Example Live ... Read More

What are accessors of properties in C#?

Chandu yadav
Updated on 23-Jun-2020 12:18:13

580 Views

Properties are an extension of fields and are accessed using the same syntax. They use accessors through which the values of the private fields can be read, written or manipulated.The accessor of a property contains the executable statements that helps in getting (reading or computing) or setting (writing) the property.Let us see an example of properties in C#.ExampleDeclare a code property of type string.public string Code {    get {       return code;    }    set {       code = value;    } }In the same way, declare Age property of type as in the ... Read More

What are the differences between public, protected and private access specifiers in C#?

Samual Sam
Updated on 23-Jun-2020 12:20:52

2K+ Views

Public Access SpecifierPublic access specifier allows a class to expose its member variables and member functions to other functions and objects. Any public member can be accessed from outside the class.Example Live Demousing System; namespace Demo {    class Rectangle {       public double length;       public double width;       public double GetArea() {          return length * width;       }         public void Display() {          Console.WriteLine("Length: {0}", length);          Console.WriteLine("Width: {0}", width);          Console.WriteLine("Area: {0}", GetArea()); ... Read More

What are abstract properties in C#?

George John
Updated on 23-Jun-2020 12:22:10

589 Views

An implementation of the property accessors will not be provided by an abstract property declaration.Let us see how to learn how to work with abstract properties. Here we have an abstract class Shape with two derived classes: Square and Circle.Here, we have an abstract Area property.The following is the Circle class.Examplepublic class Circle : Shape {    private int radius;    public Circle(int radius, string id) : base(id) {       this.radius = radius;    }    public override double Area {       get {          return radius * radius * System.Math.PI;     ... Read More

Advertisements