Interview questions for C# language

Q6: What are the Arrays in C#?

Ans: In C#, an index array begins at zero. That indicates that an array's first item begins at 0th. The last item on an array is set to sum the number of elements - 1. Thus, if there are ten arrays, then the final 10th item is 9th position.

In C#, fixed length or Dynamic arrays can be defined.

A fixed array can save several objects present.

There is no specified size for a dynamic array. When you add new items to the array, the dynamic array size rises. A fixed-length or dynamic array can be declared. After a dynamic array is established, you may even alter it to static.

Let's have a look at Simple #'s array statements. The following snippet code defines the simplest dynamic integer array with no set size.

    int[] intArray;

As you can see from the above code snippet, the declaration of an array starts with a type of array followed by a square bracket ([]) and the array's name.

The following code snippet declares an array that can store 5 items only starting from index 0 to 4.

    int[] intArray;
    intArray = new int[5];

The following code snippet declares an array that can store 100 items starting from index 0 to 99.

    int[] intArray;
    intArray = new int[100];

Q7: What is the difference between the dispose and finalize methods in C#?

Ans: In finalize and dispose, both methods are used to free unmanaged resources. Finalize

  • Dispose is also used to release unmanaged resources that are not available in the application domain at any time, such as files and database connections.
  • Manual user code directly calls Dispose.
  • If the disposal function is needed, we have to utilize the IDisposable interface to implement this class.
  • It is a part of the interface IDisposable.
  • Using a custom class to be used by other people, implement this.

Q8: Write a program in C# Sharp to find if a given string is palindrome or not?

internal static void chkPalindrome(string str) { bool flag = false; for (int i = 0, j = str.Length - 1; i < str.Length / 2; i++, j--) { if (str[i] != str[j]) { flag = false; break; } else flag = true; } if (flag) { Console.WriteLine("Palindrome"); } else Console.WriteLine("Not Palindrome");

Q9: What is the difference between public, static, and void?

Ans: The variables or methods publicly defined can be accessed anywhere in the program. Unless the instance class is established, static variables or methods defined are available globally. By default, the static member cannot be accessed globally based on the kind of access utilized. The compiler saves the method address as the input point and utilizes this information to begin execution before creating any objects. And Void is a type modifier that specifies that the method or variable does not return any value.

Q10: What are Custom Control and User Control?

Ans: Custom controls are compiled code (DLLs) controls; they may be more easily used and added to the toolbox. Developers may drag and drop web-based controls. Attributes may, at the time of design. Multiple applications can be added with individual controls (If Shared Dlls). So, if it's personal, we may copy the reference and then utilize it in dll to the bin directory of the web application.

User Controls contain files that are quite similar to ASP and can be easily created. User controls cannot be put and dragged into the toolbox — they're dumped. They have both their design and their code. The user control file extension is ascx.