Differences Between List Collection and Array in C#

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

519 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 type.To define Arrays −int[] arr = new int[5]; To initialize and set elements to Arrays −int[] arr = new int[5] {4, 8,5};

Differences Between Multi-Dimensional Array and Jagged Array

Samual Sam
Updated on 21-Jun-2020 15:13:59

1K+ Views

Multi-dimensional arrayMulti-dimensional arrays are also called rectangular array. You can define a 3-dimensional array of integer as −int [ , , ] val;Let us see how to define a two-dimensional array.int[,] val = new[3,3] Jagged arrayA Jagged array is an array of arrays. To access an element from it, just mention the index for that particular array.Here, we have a jagged array with 5 array of integers −int[][] a = new int[][]{new int[]{0,0},new int[]{1,2}, new int[]{2,4},new int[]{ 3, 6 }};

Differences Between Static and Non-Static Class in C#

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

2K+ Views

The following is the difference between a static and non-static class −Non-static classes can be instantiated, whereas static classes cannot be instantiated i.e. you cannot use the new keyword to create a variable of the class typeStatic classes can only have static methods.Non-static classes can have instance method and static methods.ou access the members of a static class by using the class name itselfStatic class is sealed.Example of static class −public static class CalculateExample of non-static class −public class Calculate

Copy or Clone a Chash List

Samual Sam
Updated on 21-Jun-2020 15:06:41

3K+ Views

To copy or clone a C# list, firstly set a list −List < string > list1 = new List < string > (); list1.Add("One"); list1.Add("Two"); list1.Add("Three"); list1.Add("Four");Now declare a string array and use the CopyTo() method to copy.string[] arr = new string[20]; list1.CopyTo(arr);Let us see the complete code to copy a list into a one-dimensional array.Exampleusing System; using System.Collections.Generic; using System.Linq; public class Demo {    public static void Main() {       List < string > list1 = new List < string > ();       list1.Add("One");       list1.Add("Two");       list1.Add("Three");   ... Read More

What is Boxing in C#

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

551 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 value types in the garbage-collected heap. It is implicit conversion of a value type to the type object.Let us see an example −Exampleusing System; using System.Collections.Generic; using System.Linq; public class Demo {    static void Main() {       int x = 50;       object ... Read More

What is C Hash Programming

karthikeya Boyini
Updated on 21-Jun-2020 15:04:37

327 Views

C# is a modern, general-purpose, object-oriented programming language developed by Microsoft.C# is designed for Common Language Infrastructure (CLI), which consists of the executable code and runtime environment that allows the use of various high-level languages on different computer platforms and architectures.Here are the features of C# −Boolean ConditionsAutomatic Garbage CollectionStandard LibraryAssembly VersioningProperties and EventsDelegates and Events ManagementEasy-to-use GenericsIndexersConditional CompilationSimple MultithreadingLINQ and Lambda ExpressionsIntegration with Windows

What is Cast Operator in C#

Ankith Reddy
Updated on 21-Jun-2020 15:03:46

816 Views

Type conversion is converting one type of data to another type. Explicit conversions are done explicitly by users using the pre-defined functions and require a cast operator.Let us see an example to cast double to int −Exampleusing System; namespace Demo {    class Program {       static void Main(string[] args) {          double a = 4563.56;          int x;          x = (int)a;          Console.WriteLine(x);          Console.ReadKey();       }    } }To cast double to int, we perfomed explicit type casting −x = (int)a;

Difference Between Implicit and Explicit Type Conversion in C#

Samual Sam
Updated on 21-Jun-2020 15:03:14

990 Views

The following is the difference between implicit and explicit type conversion −Implicit Type ConversionThese conversions are performed by C# in a type-safe manner.To understand the concept, let us implicitly convert int to long.int val1 = 11000; int val2 = 35600; long sum; sum = val1 + val2;Above, we have two integer variable and when we sum it in a long variable, it won’t show an error. Since the compiler does the implicit conversion on its own.Let us print the values now.Exampleusing System; using System.IO; namespace Demo {    class Program {       static void Main(string[] args) ... Read More

Difference Between Internal and Private Modifiers in C#

Arjun Thakur
Updated on 21-Jun-2020 15:02:21

2K+ Views

Internal Access SpecifierInternal access specifier allows a class to expose its member variables and member functions to other functions and objects in the current assembly.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 −Exampleusing System; namespace RectangleApplication {    class Rectangle {       //member variables       internal double length;       internal double width;       double GetArea() {          return length * width;       }   ... Read More

Generating OTP in Java

Fendadis John
Updated on 21-Jun-2020 15:00:56

5K+ Views

Generate OTP is now a requirement on most of the website now-a-days. In case of additional authentication, system generates a OTP password adhering to OTP policy of the company. Following example generates a unique OTP adhering to following conditions −It should contain at least one number.Length should be 4 characters.Exampleimport java.util.Random; public class Tester {    public static void main(String[] args) {       System.out.println(generateOTP(4));    }    private static char[] generateOTP(int length) {       String numbers = "1234567890";       Random random = new Random();       char[] otp = new ... Read More

Advertisements