George John has Published 1167 Articles

Private and final methods in C#

George John

George John

Updated on 21-Jun-2020 16:02:09

891 Views

Private MethodsTo set private methods, use the private access specifier.Private access specifier allows a class to hide its member variables and member functions from other functions and objects. Only functions of the same class can access its private members. Even an instance of a class cannot access its private members.Final ... Read More

How are values assigned to arrays in C#?

George John

George John

Updated on 21-Jun-2020 15:45:59

72 Views

Declaring an array does not initialize the array in the memory. When the array variable is initialized, you can assign values to the array.Array is a reference type, so you need to use the new keyword to create an instance of the array. For example, assign the values like the ... Read More

final, finally and finalize in C#

George John

George John

Updated on 21-Jun-2020 15:36:34

3K+ Views

finalJava has final keyword, but C# does not have its implementation. For the same implementation, use the sealed keyword.With sealed, you can prevent overriding of a method. When you use sealed modifiers in C# on a method, then the method loses its capabilities of overriding. The sealed method should be ... Read More

Why do we use the params keyword in C#?

George John

George John

Updated on 21-Jun-2020 15:27:16

175 Views

While declaring a method, if you are not sure of the number of arguments passed as a parameter, then use the C# param arrays.The following is the complete example to learn how to implement param in C# −Exampleusing System; namespace Program {    class ParamArray {       ... Read More

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

George John

George John

Updated on 21-Jun-2020 15:18:21

2K+ Views

The default access for a class member in C# is private.Member variables i.e. class members are the attributes of an object (from design perspective) and they are kept private to implement encapsulation. These variables can only be accessed using the public member functions.Exampleusing System; namespace RectangleApplication {    class ... Read More

What are the differences between a list collection and an array in C#?

George John

George John

Updated on 21-Jun-2020 15:14:18

362 Views

List collection is a generic class and can store any data types to create a list. To define a List −List l = new List();To set elements in a list, you need to use the Add method.l.Add("One"); l.Add("Two"); l.Add("Three");An array stores a fixed-size sequential collection of elements of the same ... Read More

What is boxing in C#?

George John

George John

Updated on 21-Jun-2020 15:05:29

423 Views

Boxing convert value type to an object type. Let us see an example of boxing −int x = 50; object ob = x; // boxingIn boxing, the value stored on the stack is copied to the object stored on heap memory, whereas unboxing is the opposite.Boxing is useful in storing ... Read More

File Handling in C#

George John

George John

Updated on 21-Jun-2020 14:34:14

571 Views

A file is a collection of data stored in a disk with a specific name and a directory path. When a file is opened for reading or writing, it becomes a stream.In C#, you need to create a FileStream object to create a new file or open an existing file. ... Read More

How to count the number of items in a C# list?

George John

George John

Updated on 21-Jun-2020 13:35:06

577 Views

Use the Array.Count property in C# to count the number of items in a list in C# −Set the listList myList = new List() {    "electronics",    "clothing",    "appliances",    "accessories" };Now count the number of items in a list in C# −myList.CountThe following is the complete code ... Read More

How to compare two Dates in C#?

George John

George John

Updated on 21-Jun-2020 13:25:22

889 Views

To compare dates in C#, you need to first set two dates to be compared using the DateTime object. We will use the DateTime class in C# −Date 1DateTime date1 = new DateTime(2018, 08, 05); Console.WriteLine("Date 1 : {0}", date1);Date 2DateTime date2 = new DateTime(2018, 08, 07); Console.WriteLine("Date 2 : ... Read More

Advertisements