Csharp Articles

Page 76 of 196

How to define multiline String Literal in C#?

George John
George John
Updated on 11-Mar-2026 1K+ Views

Let’s say the string is −Welcome User, Kindly wait for the image to loadFor multiline String Literal, firstly set it like the following statement using@ prefix −string str = @"Welcome User, Kindly wait for the image to load";Now let us display the result. The string is a multi-line string now −Exampleusing 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

Read More

How to call a method of a class in C#

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 3K+ Views

To call a method, use the name of the method after the object name, for example, −obj1. Display();Let’s say the class name is ApplicationOne, so to call the method −ApplicationOne one = new ApplicationOne(); //calling the displayMax method ret = one.displayMax(a, b);The following is the example showing how to call a method in C# −Exampleusing System; namespace Demp {    class ApplicationOne {       public int displayMax(int num1, int num2) {          /* local variable declaration */          int result;          if (num1 > num2)   ...

Read More

What are dynamic arrays in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 7K+ Views

Dynamic arrays are growable arrays and have an advantage over static arrays. This is because the size of an array is fixed.To create arrays dynamically in C#, use the ArrayList collection. It represents an ordered collection of an object that can be indexed individually. It also allows dynamic memory allocation, adding, searching and sorting items in the list.The following is an example showing how to create arrays dynamically in C# −Exampleusing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {          ArrayList al = new ArrayList(); ...

Read More

What are the differences between constructors and destructors in C#?

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 577 Views

ConstructorsA class constructor is a special member function of a class that is executed whenever we create new objects of that class.A constructor has exactly the same name as that of class and it does not have any return type.Constructor has the same name as the class name −class Demo {    public Demo() {} }The following is an example −Exampleusing System; namespace LineApplication {    class Line {       private double length; // Length of a line       public Line() {          Console.WriteLine("Object is being created");     ...

Read More

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

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 818 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 −Exampleusing 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

Read More

What are the differences between ref and out parameters in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 665 Views

Ref ParameterA reference parameter is a reference to a memory location of a variable. When you pass parameters by reference, unlike value parameters, a new storage location is not created for these parameters.You can declare the reference parameters using the ref keyword. The following is an example −Exampleusing System; namespace CalculatorApplication {    class NumberManipulator {       public void swap(ref int x, ref int y) {          int temp;          temp = x; /* save the value of x */          x = y; /* put y ...

Read More

What are static members of a C# Class?

Samual Sam
Samual Sam
Updated on 11-Mar-2026 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 the differences between class methods and class members in C#?

George John
George John
Updated on 11-Mar-2026 1K+ Views

A member function i.e. method of a class is a function that has its definition or its prototype within the class definition similar to any other variable. It operates on any object of the class of which it is a member, and has access to all the members of a class for that object.The following is an example −public void setLength( double len ) {    length = len; } public void setBreadth( double bre ) {    breadth = bre; }The following is an example showing how to access class member functions in C# −Exampleusing System; namespace ...

Read More

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

Samual Sam
Samual Sam
Updated on 11-Mar-2026 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 −Exampleusing System; namespace RectangleApplication {    class Rectangle {       //member variables       internal double length;       internal double width; ...

Read More

What is run time polymorphism in C#?

George John
George John
Updated on 11-Mar-2026 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 −Exampleusing 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
Showing 751–760 of 1,951 articles
« Prev 1 74 75 76 77 78 196 Next »
Advertisements