What are implicit type conversions in C#?

George John
Updated on 20-Jun-2020 17:03:02

184 Views

Type conversions in C# has both implicit as well as explicit type conversions. Under Implicit, the 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.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 shown an error. Since the compiler does implicit conversion on its own.Let us print the ... Read More

What are mixed arrays in C#?

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

658 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

977 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

588 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 obsolete attributes in C#?

George John
Updated on 20-Jun-2020 16:59:07

353 Views

If a method has an obsolete attribute, then the compiler issues a warning in the code after it is compiled.When a new method is being used in a class and if you still want to retain the old method in the class, you may mark it as obsolete by displaying a message the new method should be used, instead of the old method.The following is an example showing how obsolete attribute is used −using System; public class Demo {    [Obsolete("Old Method shouldn't be used! Use New Method instead", true)]    static void OldMethod() {       ... Read More

What are nested namespaces in C#?

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

1K+ 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

2K+ 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

What is ternary operator in C#?

Samual Sam
Updated on 20-Jun-2020 16:53:30

203 Views

Ternary operator is a Conditional operator in C#. It takes three arguments and evaluates a Boolean expression.For example −y = (z == 1) ? 100 : 180;Above, if the first operand evaluates to true (1), the second operand is evaluated. If the first operand evaluates to false (0), the third operand is evaluated.The following is an example −Exampleusing System; namespace Demo {    class Program {       static void Main(string[] args) {          int x, y;          x = 25;          y = (x == 25) ? 20 : 30;          Console.WriteLine("Value of x = {0}", y);          y = (x == 1) ? 50 : 90;          Console.WriteLine("Value of y = {0}", y);          Console.ReadLine();       }    } }Above we have two conditions using the ternary operators −y = (x == 25) ? 20 : 30; y = (x == 1) ? 50 : 90;

What are lambda expressions in C#?

George John
Updated on 20-Jun-2020 16:47:32

164 Views

A lambda expression in C# describes a pattern. It has the token => in an expression context. This is read as “goes to” operator and used when a lambda expression is declared.The following is an example showing how to use lambda expressions in C# −Example Live Demousing System; using System.Collections.Generic; class Demo {    static void Main() {       List list = new List() { 21, 17, 40, 11, 9 };       int res = list.FindIndex(x => x % 2 == 0);       Console.WriteLine("Index: "+res);    } }OutputIndex: 2Above, we saw the usage of ... Read More

Hashtable vs. Dictionary in C#

Chandu yadav
Updated on 20-Jun-2020 16:47:09

863 Views

HashtableA hash table is used when you need to access elements by using key, and you can identify a useful key value. Each item in the hash table has a key/value pair. The key is used to access the items in the collection.The members in a Hashtable are thread safe. It returns null if we try to find a key that does not exist. Hashtable is not a generic type.The Hashtable collection is slower than dictionary because it requires boxing and unboxing.To declare a Hashtable −Hashtable ht = new Hashtable();DictionaryDictionary is a collection of keys and values in C#. Dictionary ... Read More

Advertisements