Wednesday, August 26, 2020

Is Vs as C#?

 The difference between is and as operators are as follows: The is operator is used to check if the run-time type of an object is compatible with the given type or not whereas as operator is used to perform conversion between compatible reference types or Nullable types.

What is difference between generic and non generic in C#?

A Generic collection is a class that provides type safety without having to derive from a base collection type and implement type-specific members. The key difference between Generic and Non-generic Collection in C# is that a Generic Collection is strongly typed while a Non-Generic Collection is not strongly typed.

What is generic list in C#?

In c#, List is a generic type of collection so it will allow storing only strongly typed objects i.e. elements of the same data type, and the size of the list will vary dynamically based on our application requirements like adding or removing elements from the list.

Can we store different types in an array in C#?

In c# we use an object[] array to store different types of data in each element location. You can use an object[] (an object array), but it would be more flexible to use List<object>. It satisfies your requirement that any kind of object can be added to it, and like an array, it can be accessed through a numeric index.

List vs array in C#

Arrays are strongly typed which means it can store only specific type of items or elements. Arraylist are not strongly typed. Array cannot accept null. ArrayList can accepts null.

What are circular references in C#?

 A circular reference occurs when two or more interdependent resources cause lock condition. This makes the resource unusable.

To handle the problem of circular references in C#, you should use garbage collection. It detects and collects circular references. The garbage collector begins with local and static and it marks each object that can be reached through their children.

Through this, you can handle the issues with circular references.

Let’s say the following classes are in a circular reference. Here both of them depends on each other 

public class Hyd {

   Wgl Two;

}

public class Wgl {

   Hyd one;

}

to solve this issue using interfaces

public interface ourInterface {

}

public class Hyd{

   ourInterface Two;

}

public class Wgl: myInterface {

   Hyd one;

}