Karthikeya Boyini has Published 2193 Articles

What is default constructor in C# programs?

karthikeya Boyini

karthikeya Boyini

Updated on 20-Jun-2020 15:52:54

774 Views

A Constructor in C# is invoked automatically when an object gets created. The constructor has the same name as that of the class, for example, −public class Department {    public Department () {       Console.WriteLine("Default Constructor! ");    } }The following is the code that shows the ... Read More

How to pass parameters to a method in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 20-Jun-2020 15:40:16

240 Views

To pass parameters to a method in C#, let us see how to pass parameters by value. In this mechanism, when a method is called, a new storage location is created for each value parameter.The values of the actual parameters are copied into them. Hence, the changes made to the ... Read More

What is method overloading in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 20-Jun-2020 15:38:14

2K+ Views

Two or more than two methods having the same name but different parameters is what we call method overloading in C#.Method overloading in C# can be performed by changing the number of arguments and the data type of the arguments.Let’s say you have a function that prints multiplication of numbers, ... Read More

What is the Item property of BitArray class in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 20-Jun-2020 15:30:41

114 Views

The Item property of the BitArray class gets or sets the value of the bit at a specific position in the BitArray.Use the keyword to define the indexers instead of implementing the Item property. To access an element, use the mycollection[index].The following is the implementation of BitArray class Item property ... Read More

How to calculate the Size of Folder using C#?

karthikeya Boyini

karthikeya Boyini

Updated on 20-Jun-2020 15:26:47

4K+ Views

To calculate the size of a folder in C#, use the Directory.EnumerateFiles Method and get the files.To get the sub- directories, use the EnumerateDirectories method. Our folder is set using DirectoryInfo class −DirectoryInfo info = new DirectoryInfo(@"D:/new");Now find the size −long totalSize = info.EnumerateFiles().Sum(file => file.Length); For the directories, use ... Read More

What are postfix operators in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 20-Jun-2020 15:23:14

947 Views

The increment operator is ++ operator. If used as postfix on a variable, the value of the variable is first returned and then gets incremented by 1. It is called Postfix increment operator. In the same way, the decrement operator works but it decrements by 1.For example, a++;The following is ... Read More

What does the interface IList do in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 20-Jun-2020 15:21:31

992 Views

The IList interface has a non-generic collection of objects that can be individually accessed by index.The following are the properties of interface IList in C# −Sr.NoProperty Name & Description1CountGets the number of elements contained in the ICollection.2isFixedSizeGets a value indicating whether the IList has a fixed size.3isReadOnlyGets a value indicating ... Read More

What are the different data types of arrays in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 20-Jun-2020 15:19:31

730 Views

With C#, you can create an array of integers, chars, etc. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type stored at contiguous memory locations. This type can be ... Read More

How to display the IP Address of the Machine using C#?

karthikeya Boyini

karthikeya Boyini

Updated on 20-Jun-2020 15:10:52

784 Views

Use the IPHostEntry.AddressList Property to get IP Address −IPHostEntry myIP = Dns.GetHostEntry(hostName); IPAddress[] address = myIP.AddressList;Try the following code to display IP address −Exampleusing System; using System.Net; class Program {    static void Main() {       String hostName = string.Empty;       hostName = Dns.GetHostName();   ... Read More

Push vs pop in stack class in C#

karthikeya Boyini

karthikeya Boyini

Updated on 20-Jun-2020 15:04:44

624 Views

Stack class represents a last-in, first out collection of object. It is used when you need a last-in, first-out access of items.The following is the property of Stack class −Count − Gets the number of elements in the stack.Push OperationAdd elements in the stack using the Push operation −Stack st ... Read More

Advertisements