Base Class for All Data Types in C# .NET

karthikeya Boyini
Updated on 20-Jun-2020 17:12:27

2K+ Views

Object is the base class for all data types in C#. The Object Type is the ultimate base class for all data types in C# Common Type System (CTS). The object is an alias for System.Object class.When a value type is converted to object type, it is called boxing and on the other hand, when an object type is converted to a value type, it is called unboxing.The following is an example showing the usage of object data types −using System; using System.IO; namespace Demo {    class objectClass {       public int x = 56;   ... Read More

Use LINQ to Sort a List in C#

Samual Sam
Updated on 20-Jun-2020 17:11:01

768 Views

Use the LINQ orderby keyword to sort a list in C#.In the below example, we have set the orderby for the elements −var myLen = from element in myList orderby element.Length select element;Let us see an example −Example Live Demousing System; using System.Collections.Generic; using System.Linq; class Demo {    static void Main() {       List myList = new List();       myList.Add("truck");       myList.Add("bus");       myList.Add("cab");       myList.Add("motorbike");       var myLen = from element in myList       orderby element.Length       select element; ... Read More

Use NameValueCollection Class in C#

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

734 Views

The NameValueCollection sets more than one value for a single key. Now let us see how to use them in our C# program.Set the collection −static NameValueCollection GetCollection() {    NameValueCollection myCollection = new NameValueCollection();    myCollection.Add("Tim", "One");    myCollection.Add("John", "Two");    myCollection.Add("Jamie", "Three");    return myCollection; }Now with the GetCollection() method use the “AllKeys” method property to display all the keys −NameValueCollection myCollection = GetCollection(); foreach (string key in myCollection.AllKeys) {    Console.WriteLine(key); }

What are Finalizers in C#

Ankith Reddy
Updated on 20-Jun-2020 17:09:55

1K+ Views

Finalizers in C# are used to destruct instances of classes. With that, you can also use it to release resources.Here are some of the key points about Finalizers −Only one finalizer is allowed for a classYou cannot inherit or overload FinalizersA finalizer cannot have parametersFinalizers invoke automaticallyFinalizers in C# are declared like destructors. Let’s say the class name is Demo, therefore, the following would be our finalizer −~Demo() {    // }The finalizer declaration is prefixed with a tilde before the class name.

What are Reference Data Types in C#

Chandu yadav
Updated on 20-Jun-2020 17:06:41

2K+ Views

The reference data type in C# does not have the actual data stored in a variable, but they contain a reference to the variables.In C#, the following are the built-in reference types −Object TypeThe Object Type is the ultimate base class for all data types in C# Common Type System (CTS). The object types can be assigned values of any other types, value types, reference types, predefined or user-defined types.Exampleobject ob; ob = 250; // boxingDynamic TypeStore any type of value in the dynamic data type variable. Type checking for these types of variables takes place at run-time.Exampledynamic d = ... Read More

What are Mixed Arrays in C#

Chandu yadav
Updated on 20-Jun-2020 17:02:28

1K+ Views

Mixed arrays are a combination of multi-dimension arrays and jagged arrays.Note − The mixed arrays type is obsolete now since .NET 4.0 update removed it.Let us see how you can declare a mixed array −var x = new object[] {89, 45, "jacob", 9.8}We can also set them as −var x = new object[] {87, 33, "tim", 6.7, new List() {"football", "tennis", "squash", “cricket”} }Since, mixed arrays are obslete now. For the same work, use the List collection. Here, we have set int and string in the list −Tuple tuple = new Tuple(60, "John");The same example is displayed below:using System; using ... Read More

What are Objects in C#

Arjun Thakur
Updated on 20-Jun-2020 17:01:58

1K+ Views

Like any other object-oriented language, C# also has object and classes. Objects are real-world entities and instance of a class. Access the members of the class using an object.To access the class members, you need to use the dot (.) operator after the object name. The dot operator links the name of an object with the name of a member, for example, Box b1 = new Box();Above you can see Box1 is our object. We will use it to access the members −b1.height = 7.0;You can also use it to call member functions −b1.getVolume();The following is an example showing how ... Read More

What are Object Data Types in C#

Ankith Reddy
Updated on 20-Jun-2020 17:00:10

1K+ Views

The object types can be assigned values of any other types, value types, reference types, predefined or user-defined types. However, before assigning values, it needs type conversion.The Object Type is the ultimate base class for all data types in C# Common Type System (CTS). Object is an alias for System.Object class.When a value type is converted to object type, it is called boxing and on the other hand, when an object type is converted to a value type, it is called unboxing.The following is an example −object obj; obj = 100; // this is boxingHere is the complete example showing ... Read More

What are Nested Namespaces in C#

Ankith Reddy
Updated on 20-Jun-2020 16:58:33

2K+ Views

A namespace inside a namespace is called a nested namespace in C#. This is mainly done to properly structure your code.We have an outer namespace −namespace outer {}Within that, we have an inner namespace inside the outer namespace −namespace inner {    public class innerClass {       public void display() {          Console.WriteLine("Inner Namespace");       }    } }Now to call the method of inner namespace, set a class object of the inner class and call the method as shown in the below example −namespace outer {    class Program {   ... Read More

Process Management

Amit Diwan
Updated on 20-Jun-2020 16:57:05

4K+ Views

A process is an active program i.e a program that is under execution. It contains the program code, program counter, process stack, registers etc.Process StatesThe different states that a process is in during its execution are explained using the following diagram −New- The process is in new state when it has just been created.Ready - The process is waiting to be assigned the processor by the short term scheduler.Running - The process instructions are being executed by the processor.Waiting - The process is waiting for some event such as I/O to occur.Terminated - The process has completed its execution.Process Control ... Read More

Advertisements