Server Side Programming Articles - Page 2532 of 2650

What is the Capacity property of SortedList class in C#?

Ankith Reddy
Updated on 20-Jun-2020 10:45:43

343 Views

The capacity property in SortedList class has the maximum size of the SortedList.The default capacity of a SortedList is 16.You can try to run the following the code to implement Capacity property of SortedList class in C# −Example Live Demousing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] args) {          SortedList s = new SortedList();          s.Add("S1", "Maths");          s.Add("S2", "Science");          s.Add("S3", "English");          s.Add("S4", "Economics");          Console.WriteLine("Capacity = " ... Read More

What is the Count property of ArrayList class in C#?

Samual Sam
Updated on 20-Jun-2020 10:46:48

290 Views

The Count property in the ArrayList class counts the number of elements in the ArrayList.Firstly, add elements to the ArrayList −ArrayList arrList = new ArrayList(); arrList.Add(98); arrList.Add(55); arrList.Add(65); arrList.Add(34);Then get the count of the array list −arrList.CountThe following is the code to implement Count property in C# −Example Live Demousing System; using System.Collections; class Demo {    public static void Main() {       ArrayList arrList = new ArrayList();       arrList.Add(98);       arrList.Add(55);       arrList.Add(65);       arrList.Add(34);       Console.WriteLine("Count = " + arrList.Count);    } }OutputCount = 4

What is the Capacity property of an ArrayList class in C#?

karthikeya Boyini
Updated on 20-Jun-2020 10:47:28

3K+ Views

The capacity property in ArrayList class gets or sets the number of elements that the ArrayList can contain.Capacity is always greater than count. For capacity property −arrList.CapacityThe default capacity is 4. If 5 elements are there, then its capacity is doubled and would be 8. This goes on.You can try to run the following the code to implement Capacity property in C#. This also shows what we discussed above −Example Live Demousing System; using System.Collections; class Demo {    public static void Main() {       ArrayList arrList = new ArrayList();       arrList.Add(19);       arrList.Add(44); ... Read More

How do you find the number of dimensions of an array in C#?

Samual Sam
Updated on 20-Jun-2020 10:48:43

943 Views

To find the number of dimensions of an array, use the Rank property.arr.RankHere, arr is our array −int[, ] arr = new int[3, 4];If you also want to get the rows and columns it 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[3, 4];       Console.WriteLine(arr.GetLength(0));       Console.WriteLine(arr.GetLength(1));       // Length       Console.WriteLine(arr.Length);       Console.WriteLine("Upper Bound: {0}", arr.GetUpperBound(0).ToString());       Console.WriteLine("Lower Bound: ... Read More

How do you find the length of an array in C#?

George John
Updated on 20-Jun-2020 10:48:01

18K+ Views

To find the length of an array, use the Array.Length() method.ExampleLet us see an example − Live Demousing System; class Program {    static void Main(){       int[] arr = new int[10];       // finding length       int arrLength = arr.Length;       Console.WriteLine("Length of the array: "+arrLength);    } }OutputLength of the array: 10Above, we have an array −int[] arr = new int[10];Now to find the length, we used the Length() method −int arrLength = arr.Length;

How to use sizeof() operator to find the size of a data type or a variable in C#

karthikeya Boyini
Updated on 20-Jun-2020 10:51:08

356 Views

The sizeof() datatype returns the size of a data type. Let’s say you need to find the size of int datatype −sizeof(int);For double datatypesizeof(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 {0}", sizeof(char));          Console.WriteLine("The size of short is {0}", sizeof(short));          Console.WriteLine("The size of long is ... Read More

Command Line arguments in C#

Samual Sam
Updated on 20-Jun-2020 10:51:53

3K+ Views

If you want to pass arguments by command line, then use command line arguments in C# −When we create a program in c#, static void main is used and we can see the arguments in it .class HelloWorld {    static void Main(string[] args) {       /* my first program in C# */       Console.WriteLine("Hello World");       Console.ReadKey();    }The string[] args is a variable that has all the values passed from the command line as shown above.Now to print those arguments, let’s say we have an argument, “One” −Console.WriteLine("Length of the arguments: "+args.Length); ... Read More

How do you empty an array in C#?

Chandu yadav
Updated on 20-Jun-2020 10:52:35

20K+ Views

To empty an array in C#, use the Array Clear() method: The Array.Clear method in C# clears i.e.zeros out all elements.In the below example, we have first considered an array with three elements −int[] arr = new int[] {88, 45, 76};Now we have used the Array.Clear method to zero out all the arrays −Array.Clear(arr, 0, arr.Length);Let us see an example of Array.Clear method in c# −Example Live Demousing System; class Program {    static void Main() {       int[] arr = new int[] {88, 45, 76};       Console.WriteLine("Array (Old):");       foreach (int val in arr) ... Read More

Cloning in C#

karthikeya Boyini
Updated on 20-Jun-2020 10:52:59

390 Views

Cloning in C# is useful if you want to clone an array. The Clone() method in C# is used to create a similar copy of the array. C# has the Clone method and ICloneable interface.Let us see an example to clone an array using the Clone() method −Example Live Demousing System; class Program {    static void Main() {       string[] arr = { "one", "two", "three", "four", "five" };       string[] arrCloned = arr.Clone() as string[];       Console.WriteLine(string.Join(", ", arr));       Console.WriteLine(string.Join(", ", arrCloned));       Console.WriteLine();    } ... Read More

What is Type casting in C#?

Samual Sam
Updated on 20-Jun-2020 10:38:06

414 Views

Type casting is converting one type of data to another type. The two forms are −Implicit type conversion − These conversions are performed by C# in a type-safe manner. For example, are conversions from smaller to larger integral types and conversions from derived classes to base classes.Explicit type conversion− These conversions are done explicitly by users using the pre-defined functions. Explicit conversions require a cast operator.The following are the built-in type conversion methods −Sr.NoMethod & Description1ToBooleanConverts a type to a Boolean value, where possible.2ToByteConverts a type to a byte.3ToCharConverts a type to a single Unicode character, where possible.4ToDateTimeConverts a type ... Read More

Advertisements