Server Side Programming Articles - Page 2527 of 2650

What is the difference between a class and an object in C#?

karthikeya Boyini
Updated on 20-Jun-2020 12:58:55

323 Views

When you define a class, you define a blueprint for a data type.Objects are instances of a class. The methods and variables that constitute a class are called members of the class.To access the class members, you use the dot (.) operator after the object name. The dot operator links the name of an object with the name of a member for example, Box Box1 = new Box();Above you can see Box1 is our object. We will use it to access the members −Box1.height = 7.0;You can also use it to call member functions −Box1.getVolume();The following is an example showing ... Read More

What is run time polymorphism in C#?

George John
Updated on 18-Mar-2020 06:22:06

2K+ Views

Runtime polymorphism has method overriding that is also known as dynamic binding or late binding. It is implemented by abstract classes and virtual functions.Abstract ClassesAbstract classes contain abstract methods, which are implemented by the derived class.Let us see an example of abstract classes that implements run time polymorphism −Example Live Demousing System; namespace PolymorphismApplication {    abstract class Shape {       public abstract int area();    }    class Rectangle: Shape {       private int length;       private int width;       public Rectangle( int a = 0, int b = 0) {     ... Read More

What is the default access for a class in C#?

Samual Sam
Updated on 20-Jun-2020 13:08:55

1K+ Views

If no access modifier is specified, then the default is Internal. Internal access specifier allows a class to expose its member variables and member functions to other functions and objects in the current assembly. In other words, any member with internal access specifier can be accessed from any class or method defined within the application in which the member is defined.The following is an example showing the usage of Internal access specifier −Example Live Demousing System; namespace RectangleApplication {    class Rectangle {       //member variables       internal double length;       internal double width; ... Read More

What are static member functions in C#?

karthikeya Boyini
Updated on 20-Jun-2020 13:09:32

697 Views

Static functions can access only static variables. The static functions exist even before the object is created.Set static functions as −public static int getNum() {}The following is an example demonstrating the use of static functions −Example Live Demousing System; namespace Demo {    class StaticVar {       public static int num;       public void count() {          num++;       }       public static int getNum() {          return num;       }    }    class StaticTester {       static void Main(string[] args) {          StaticVar s = new StaticVar();          s.count();          s.count();          s.count();          Console.WriteLine("Variable num: {0}", StaticVar.getNum());          Console.ReadKey();       }    } }OutputVariable num: 3

What are static members of a C# Class?

Samual Sam
Updated on 20-Jun-2020 13:10:49

5K+ Views

We can define class members as static using the static keyword. When we declare a member of a class as static, it means no matter how many objects of the class are created, there is only one copy of the static member.The keyword static implies that only one instance of the member exists for a class. Static variables are used for defining constants because their values can be retrieved by invoking the class without creating an instance of it. Static variables can be initialized outside the member function or class definition. You can also initialize static variables inside the class ... Read More

What are nested classes in C#?

karthikeya Boyini
Updated on 20-Jun-2020 13:11:19

344 Views

A nested class is a class declared in another enclosing class. It is a member of its enclosing class and the members of an enclosing class have no access to members of a nested class.Let us see an example code snippet of nested classes in C# −class One {    public int num1;    public class Two {       public int num2;    } } class Demo {    static void Main() {       One a = new One();       a.num1++;       One.Two ab = new One.Two();     ... Read More

What is the difference between a float, double and a decimal in C#?

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

2K+ Views

Float , double and a decimal are all Value Types in C#. Value type variables can be assigned a value directly. They are derived from the class System.ValueType. The value types directly contain data. Float Value Type Float is a 32-bit single-precision floating point type with range 3.4 x 1038 to + 3.4 x 1038 Memory Size is 4 bytes. float a = 3.5f; Double Value Type Double is a 64-bit double-precision floating point type with range (+/-)5.0 x 10-324 to (+/-)1.7 x 10308 Memory Size is 8 bytes. double d = 5.78788 Decimal Value ... Read More

How to use RemoveAt in C# ArrayList?

George John
Updated on 20-Jun-2020 12:47:41

484 Views

The RemoveAt method in C# is used to remove an element in a list at a position you set.Firstly, set elements in the list −var subjects = new List(); subjects.Add("Physics"); subjects.Add("Chemistry"); subjects.Add("Biology"); subjects.Add("Science");To remove an element, set the index from where you want to eliminate the element. The following is to remove element from the 3rd position −subjects.RemoveAt(2);Let us see the complete code −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(string[] args){       var subjects = new List();       subjects.Add("Physics");       subjects.Add("Chemistry");       subjects.Add("Biology");   ... Read More

What does the @ prefix do on string literals in C#?

Chandu yadav
Updated on 20-Jun-2020 12:50:07

763 Views

The @prefix states hat you don't need to escape special characters in the string following to the symbol.The following statement@"D:ew"is equal to:"D:ew"The @ prefix is also used if you want to have large strings and want it to be displayed across multiple lines. The following is an example showing multi-line string −Example Live Demousing System; namespace Demo {    class Program {       static void Main(string[] args) {          string str = @"Welcome User,          Kindly wait for the image to          load";          Console.WriteLine(str);       }    } }OutputWelcome User, Kindly wait for the image to load

What does Array.Rank property of array class do in C#?

karthikeya Boyini
Updated on 20-Jun-2020 12:50:42

306 Views

Let us see an example to find the number of dimensions of an array, using the Rank property.arr.RankHere, arr is our array −int[, ] arr = new int[5, 5];If you want to get the rows and columns the array has, then use the GetLength property −arr.GetLength(0); arr.GetLength(1);The following is the complete code −Example Live Demousing System; class Program {    static void Main() {       int[, ] arr = new int[4, 5];       Console.WriteLine(arr.GetLength(0));       Console.WriteLine(arr.GetLength(1));       Console.WriteLine("Upper Bound: {0}", arr.GetUpperBound(0).ToString());       Console.WriteLine("Lower Bound: {0}", arr.GetLowerBound(0).ToString());     ... Read More

Advertisements