Found 2628 Articles for Csharp

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

Chandu yadav
Updated on 20-Jun-2020 13:23:53

191 Views

The IsFixedSize property of ArrayList class is used to get a value indicating whether the ArrayList has a fixed size.The following is an example stating the usage of isFixedSize property −Example Live Demousing System; using System.Collections; class Demo {    public static void Main() {       ArrayList arrList = new ArrayList();       Console.WriteLine("Adding some numbers:");       arrList.Add(45);       arrList.Add(78);       Console.WriteLine(arrList.Count);       Console.WriteLine("myArrayList.IsFixedSize = " + arrList.IsFixedSize);     } }OutputAdding some numbers: 2 myArrayList.IsFixedSize = FalseAbove we have added an array list −ArrayList arrList ... Read More

What is finally statement in C#?

Samual Sam
Updated on 20-Jun-2020 13:24:44

258 Views

The final block is used to execute a given set of statements, whether an exception is thrown or not thrown. For example, if you open a file, it must be closed whether an exception is raised or not.The error handling blocks are implemented using the try, catch, and finally keywords.ExampleYou can try to run the following code to implement finally statement −using System; namespace ErrorHandlingApplication {    class DivNumbers {       int result;       DivNumbers() {          result = 0;       }       public void division(int ... Read More

What is enumeration in C#?

karthikeya Boyini
Updated on 20-Jun-2020 13:27:04

130 Views

Enum is Enumeration to store a set of named constants like a year, product, month, season, etc.The default value of Enum constants starts from 0 and increments. It has a fixed set of constants and can be traversed easily.Let us see an example.We have set the enum like this −public enum Vehicle { Car, Bus, Truck }The following is the complete example −Example Live Demousing System; public class Demo {    public enum Vehicle { Car, Bus, Truck }    public static void Main() {       int a = (int)Vehicle.Car;       int b = (int)Vehicle.Bus; ... Read More

What is encapsulation in C#?

Ankith Reddy
Updated on 20-Jun-2020 13:14:00

313 Views

Encapsulation in C# prevents access to implementation details. Implement Encapsulation in C# using access specifiers.The following are the access specifiers supported by C# −PublicPrivateProtectedInternalProtected internalEncapsulation can be understood by taking an example of private access specifier that allows a class to hide its member variables and member functions from other functions and objects.In the following example we have length and width as variables assigned private access specifier −Example Live Demousing System; namespace RectangleApplication {    class Rectangle {       private double length;       private double width;       public void Acceptdetails() {     ... Read More

What is aggregation in C#?

Arjun Thakur
Updated on 20-Jun-2020 13:15:21

263 Views

Aggregation is a directional relation between objects in C#. It is the relationship between objects.For example, Employee and AddressAn Employee is associated with a single Department, whereas a Department can have more than one employee. Let us see an example of Employee and Address −public class Address {    . . . } public class Employee {    private Address addr;    public Employee (Address addr) {       this.addr = addr;    }    . . . }

What are user-defined exceptions in C#?

karthikeya Boyini
Updated on 20-Jun-2020 13:16:08

527 Views

Like any other programming language, in C#, you can easily create a user-defined exception. User-defined exception classes are derived from the Exception class. Custom exceptions are what we call user-defined exceptions.In the below example, the exception created is not a built-in exception; it is a custom exception −TempIsZeroExceptionYou can try to run the following code to learn how to create a user-defined exception in C# −Example Live Demousing System; namespace Demo {    class TestTemperature {       static void Main(string[] args) {          Temperature temp = new Temperature();          try {   ... Read More

What are user defined data types in C#?

Chandu yadav
Updated on 20-Jun-2020 13:16:48

2K+ Views

The User defined data types in C# are structures and enumeration.StructureIn C#, a structure is a value type data type. It helps you to make a single variable hold related data of various data types. The struct keyword is used for creating a structure.The C# structures have the following features −Structures can have methods, fields, indexers, properties, operator methods, and events.Structures can have defined constructors, but not destructors. However, you cannot define a default constructor for a structure. The default constructor is automatically defined and cannot be changed.Unlike classes, structures cannot inherit other structures or classes.Structures cannot be used as ... Read More

What are unary operators in C#?

Samual Sam
Updated on 20-Jun-2020 13:17:19

249 Views

The following are the unary operators in C# −+ - ! ~ ++ -- (type)* & sizeofLet us learn about the sizeof operator. The sizeof returns the size of a data type.Let’s say you need to find the size of int datatype −sizeof(int)For double datatype −sizeof(double)Let us see the complete example to find the size of various datatypes −Example Live Demousing System; namespace Demo {    class Program {       static void Main(string[] args) {          Console.WriteLine("The size of int is {0}", sizeof(int));          Console.WriteLine("The size of int is ... Read More

What is early binding in C#?

Arjun Thakur
Updated on 20-Jun-2020 13:18:04

770 Views

The mechanism of linking a function with an object during compile time is called early binding. It is also called static binding. C# provides two techniques to implement static polymorphism i.e Function overloading and Operator overloading.Let us learn about Function Overloading with an example −You can have multiple definitions for the same function name in the same scope. The definition of the function must differ from each other by the types and/or the number of arguments in the argument list. You cannot overload function declarations that differ only by return type.The following is the complete example −Example Live Demousing System; ... Read More

What is dynamic binding in C#?

karthikeya Boyini
Updated on 20-Jun-2020 13:18:34

407 Views

In Dynamic binding, the compiler will not do type checking at compile time. At runtime, the checking is done.Use it to avoid the restriction of anonymous types to one method. This is only because the type name is visible only to the compiler; therefore, you cannot declare it as the return value of a method.Let us see an example −public dynamic GetAnonymousType() {    return new {       StudentName = "Jack",       Subject = "Maths",    }; }Above, the method is set to be dynamic, that would mean the compiler won’t do type checking at compile time −public dynamic GetAnonymousType() {}

Advertisements