Found 2587 Articles for Csharp

How to store n number of lists of different types in a single generic list in C#?

Nizamuddin Siddiqui
Updated on 04-Aug-2020 06:30:13

796 Views

We can store n number of lists of different types in a single generic list by creating a list of list of objects as shown below.List list = new List();Example Live Demousing System; using System.Collections.Generic; namespace MyApplication{    public class Program{       public static void Main(){          List list = new List();          List list1 = new List();          list1.Add(101);          list1.Add(102);          list1.Add(103);          list.Add(list1);          List list2 = new List();          list2.Add("Test1");   ... Read More

What is the use of "is" keyword in C#?

Nizamuddin Siddiqui
Updated on 04-Aug-2020 06:28:19

378 Views

The "is" keyword is used to check if an object can be casted to a specific type. The return type of the operation is Boolean.Exampleusing System; namespace DemoApplication{    class Program{       static void Main(){          Employee emp = new PermanentEmployee{             ID = 1,             Name = "Martin"          };          // Returns true as the derived type can be converted to base type.          if (emp is Employee){             ... Read More

What if we are not sure of the type of value that we want to store in a variable. How to handle this in C#?

Nizamuddin Siddiqui
Updated on 04-Aug-2020 06:25:55

90 Views

As C# is a strongly-typed language, every variable and constant has a pre-defined type. Before using any variable, we must tell the compiler what type of value a variable will store.If we are not sure about the type, then it is handled using dynamic programming. Dynamic programming is supported by the dynamic keyword.The dynamic keyword is used to declare dynamic types. The dynamic types tell the compiler that the object is defined as dynamic and skip type-checking at compiler time, delay type-checking until runtime. All syntaxes are checked and errors are thrown at runtime.Example Live Demousing System; namespace DemoDynamicKeyword{    class ... Read More

Difference between Method Overriding and Method Hiding in C#

Nitin Sharma
Updated on 09-Jun-2020 09:13:22

3K+ Views

In C# there are two mechanisms for redefining or providing the new implementation of a method of parent class by its child class and these two mechanisms are known as Method overriding and Method hiding. Now on the basis of how method re-implementation is done we can distinguish between both of them.Following are the important differences between Method Overriding and Method Hiding.Sr. No.KeyMethod OverridingMethod Hiding1DefinitionMethod Overriding is a mechanism to achieve polymorphism where the super class and sub class have same methods, including the parameters and signature and, when you call it using the sub class object, the implementation in ... Read More

Difference between SortedList and SortedDictionary in C#

Nitin Sharma
Updated on 09-Jun-2020 09:09:16

877 Views

Both SortedList and SortedDictionary in C# are the types of data structures used for data storage, now on the basis of characteristics and nature we can distinguish between both of them.Following are the important differences between SortedList and SortedDictionary.Sr. No.KeySortedListSortedDictionary1Memory organizationSortedList requires low memory for storage hence the memory status in its case is overhead.On other hand SortedDictionary requires more memory for storage so memory status in its case is not bottlenecked.2DesignedSortedList is internally implemented as in sortedList the elements are stored in a continuous block in memory.On other hand in SortedDictionary the elements are stored in separate object that ... Read More

Difference between Class and Structure in C#

Nitin Sharma
Updated on 09-Jun-2020 08:36:53

934 Views

In order to differentiate between Class and Structure, we have to first understand that both structure and class seems to be equivalent in the context of holding and defining the data. Both of these could define as well as hold some default values in their data members. But if we consider them beyond this context then Class provides more flexibility along with functionality as compared to the Structure.Following are the important differences between Class and Structure.Sr. No.KeyClassStructure1Data TypeData defined in a class is stored in the memory as a reference and has particular address in order to get accessed, so ... Read More

Difference between HashTable and Dictionary in C#

Nitin Sharma
Updated on 09-Jun-2020 07:51:55

6K+ Views

Both HashTable and Dictionary are the type of data structure which are used to store data. Both of these data structures hold the stored data in key value pair.On the basis of difference between key features of these we can distinguish between HashTable and Dictionary as follows −Sr. No.KeyHashTableDictionary1DefinitionHashTable is the non-generic type of collection which is used to store data in key/value pair and is defined in System.Collections name space.On other hand Dictionary is a generic type collection defined under System.Collection.Generics name space which also store data in the form of key/value pairs.2DataTypeIn HashTable same or different data type ... Read More

Difference between out and ref keyword in C#

Mahesh Parahar
Updated on 16-May-2020 14:16:00

19K+ Views

out keywordout keyword is used to pass arguments to method as a reference type and is primary used when a method has to return multiple values. ref keyword is also used to pass arguments to method as reference type and is used when existing variable is to be modified in a method. Following is the valid usage of ref and out keywords in C#.Example Live Demousing System.IO; using System; public class Program {    public static void update(out int a){       a = 10;    }    public static void change(ref int d){       d = 11; ... Read More

Difference between readonly and const keyword in C#

Mahesh Parahar
Updated on 16-May-2020 14:14:55

12K+ Views

readonly keywordreadonly keyword is used to define a variable which can be assigned once after declaration either during declaration or in constructor. const keyword is used to define a constant to be used in the program. Following is the valid usage of a readonly and const keywords in C#.Example Live Demousing System.IO; using System; public class Program {    public const int VALUE = 10;    public readonly int value1;    Program(int value){       value1 = value;    }    public static void Main() {       Console.WriteLine(VALUE);       Program p1 = new Program(11); ... Read More

Executing C# code in Linux

Ajay yadav
Updated on 05-Jan-2021 06:38:26

5K+ Views

The .NET centric applications are meant to windows operating system up till now, but now Microsoft has introduced a new cross-platform application called Mono which enables the execution of the application developed under the .NET platform in Linux environment by giving an impression in such a way that as if we are running Linux package rather than executing .exe file.MonoMono is an open-source utility that allows the developer to execute .NET centric applications on other platforms such as Mac or Linux as it provides an installation package for Windows platform to compile and execute .NET assemblies on Windows OS without ever ... Read More

Advertisements