{"id":1707,"date":"2023-06-14T06:58:22","date_gmt":"2023-06-14T06:58:22","guid":{"rendered":"http:\/\/waqar-arshad.com\/?p=1707"},"modified":"2023-06-14T07:43:53","modified_gmt":"2023-06-14T07:43:53","slug":"net-top-50-interview-questions","status":"publish","type":"post","link":"http:\/\/waqar-arshad.com\/index.php\/2023\/06\/14\/net-top-50-interview-questions\/","title":{"rendered":".Net Top 50 Interview Questions"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"1707\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><div class=\"pld-dislike-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-dislike-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"1707\" data-trigger-type=\"dislike\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-down\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-dislike-count-wrap pld-count-wrap\"><\/span>\r\n<\/div><\/div>\n<p><strong>C# Interview Questions and Answers <\/strong><strong><\/strong><\/p>\n\n\n\n<p>Here are C# interview questions and answers for fresher as well 5 or 10 years experienced candidates to get their dream job.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>1) What is the role of C#?<\/strong><strong><\/strong><\/p>\n\n\n\n<p><strong>Sample answer:<\/strong><\/p>\n\n\n\n<p>The role of C# as a programming language is to precisely define a set of operations that a computer can perform to complete a task. It\u2019s used to create desktop apps, mobile apps, web apps, websites, and web services.<\/p>\n\n\n\n<p><strong>2) What is meant by object-oriented programming?<\/strong><strong><\/strong><\/p>\n\n\n\n<p><strong>Sample answer:<\/strong><\/p>\n\n\n\n<p>Object-oriented programming (OOP) is an approach to programming where software is primarily designed by using objects (essentially data) that interact with each other.&nbsp;<\/p>\n\n\n\n<p>When different pieces of data are put together, they come to form the software as a whole. OOP is an alternative to functional or procedural programming and it\u2019s also the approach used by C#.<\/p>\n\n\n\n<p><strong>3) Can multiple catch blocks be executed?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>No, Multiple catch blocks of similar type can\u2019t be executed. Once the proper catch code executed, the control is transferred to the finally block, and then the code that follows the finally block gets executed.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>4) What is the difference between public, static, and void?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>Public declared variables or methods are accessible anywhere in the application. Static declared variables or methods are globally accessible without creating an instance of the class. Static member are by default not globally accessible it depends upon the type of access modified used. The compiler stores the address of the method as the entry point and uses this information to begin execution before any objects are created. And Void is a type modifier that states that the method or variable does not return any value.<\/p>\n\n\n\n<p>C# interview questions<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>7) What is Jagged Arrays?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>The Array which has elements of type array is called jagged Array. The elements can be of different dimensions and sizes. We can also call jagged Array as an Array of arrays.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>8) What is the difference between ref &amp; out parameters?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>An argument passed as ref must be initialized before passing to the method whereas out parameter needs not to be initialized before passing to a method.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>9) What is the use of \u2018using\u2019 statement in C#?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>The \u2018using\u2019 block is used to obtain a resource and process it and then automatically dispose of when the execution of the block completed.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>11) Can we use \u201cthis\u201d command within a static method?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>We can\u2019t use \u2018This\u2019 in a static method because we can only use static variables\/methods in a static method.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>12) What is the difference between constants and read-only?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>Constant variables are declared and initialized at compile time. The value can\u2019t be changed afterward. Read-only is used only when we want to assign the value at run<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>18) What is the difference between Array and Arraylist?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>In an array, we can have items of the same type only. The size of the array is fixed when compared. To an arraylist is similar to an array, but it doesn\u2019t have a fixed size.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>19) Can a private virtual method can be overridden?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>No, because they are not accessible outside the class.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>20) Describe the accessibility modifier \u201cprotected internal\u201d.<\/strong><strong><\/strong><\/p>\n\n\n\n<p>Protected Internal variables\/methods are accessible within the same assembly and also from the classes that are derived from this parent class.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>23) How can we sort the elements of the Array in descending order?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>Using&nbsp;Sort()&nbsp;methods followed by&nbsp;Reverse()&nbsp;method.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>25) What\u2019s the difference between an interface and abstract class?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>Interfaces have all the methods having only declaration but no definition. In an abstract class, we can have some concrete methods. In an interface class, all the methods are public. An abstract class may have private methods.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>26) What is the difference between Finalize() and Dispose() methods?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>Dispose()&nbsp;is called when we want for an object to release any unmanaged resources with them. On the other hand,&nbsp;Finalize()&nbsp;is used for the same purpose, but it doesn\u2019t assure the garbage collection of an object.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>27) What are circular references?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>Circular reference is situation in which two or more resources are interdependent on each other causes the lock condition and make the resources unusable.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>28) What are generics in C#.NET?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>Generics are used to make reusable code classes to decrease the code redundancy, increase type safety, and performance. Using generics, we can create collection classes. To create generic collection, System.Collections.Generic namespace should be used instead of classes such as ArrayList in the System.Collections namespace. Generics promotes the usage of parameterized types.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>29) What is an object pool in .NET?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>An object pool is a container having objects ready to be used. It tracks the object that is currently in use, total number of objects in the pool. This reduces the overhead of creating and re-creating objects.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>30) List down the commonly used types of exceptions in .net<\/strong><strong><\/strong><\/p>\n\n\n\n<p>ArgumentException, ArgumentNullException, ArgumentOutOfRangeException, ArithmeticException, DivideByZeroException ,OverflowException, IndexOutOfRangeException, InvalidCastException, InvalidOperationException, IOEndOfStreamException , NullReferenceException, OutOfMemoryException, StackOverflowException etc.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>35) What is the difference between method overriding and method overloading?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>In method overriding, we change the method definition in the derived class that changes the method behavior. Method overloading is creating a method with the same name within the same class having different signatures.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>36) What are the different ways a method can be overloaded?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>Methods can be overloaded using different data types for a parameter, different order of parameters, and different number of parameters.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>37) Why can\u2019t you specify the accessibility modifier for methods inside the interface?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>In an interface, we have virtual methods that do not have method definition. All the methods are there to be overridden in the derived class. That\u2019s why they all are public.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>38) How can we set the class to be inherited, but prevent the method from being over-ridden?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>Declare the class as public and make the method sealed to prevent it from being overridden.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>39) What happens if the inherited interfaces have conflicting method names?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>Implement is up to you as the method is inside your own class. There might be a problem when the methods from different interfaces expect different data, but as far as compiler cares you\u2019re okay.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>40) What is the difference between a Struct and a Class?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>Structs are value-type variables, and classes are reference types. Structs stored on the Stack causes additional overhead but faster retrieval. Structs cannot be inherited.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>41) How to use nullable types in .Net?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>Value types can take either their normal values or a null value. Such types are called nullable types.<\/p>\n\n\n\n<p>Int? someID = null;<\/p>\n\n\n\n<p>If(someID.HasVAlue)<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>42) How we can create an array with non-default values?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>We can create an array with non-default values using Enumerable.Repeat.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>43) What is difference between \u201cis\u201d and \u201cas\u201d operators in c#?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>\u201cis\u201d operator is used to check the compatibility of an object with a given type, and it returns the result as Boolean.<\/p>\n\n\n\n<p>\u201cas\u201d operator is used for casting of an object to a type or a class.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>44) What\u2019s a multicast delegate?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>A delegate having multiple handlers assigned to it is called multicast delegate. Each handler is assigned to a method.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>45) What are indexers in C# .NET?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>Indexers are known as smart arrays in C#. It allows the instances of a class to be indexed in the same way as an array.<\/p>\n\n\n\n<p>Eg:<\/p>\n\n\n\n<p>public int this[int index]&nbsp;&nbsp;&nbsp; \/\/ Indexer declaration<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>46) What is difference between the \u201cthrow\u201d and \u201cthrow ex\u201d in .NET?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>\u201cThrow\u201d statement preserves original error stack whereas \u201cthrow ex\u201d have the stack trace from their throw point. It is always advised to use \u201cthrow\u201d because it provides more accurate error information.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>47) What are C# attributes and its significance?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>C# provides developers a way to define declarative tags on certain entities, eg. Class, method, etc. are called attributes. The attribute\u2019s information can be retrieved at runtime using Reflection.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>48) How to implement a singleton design pattern in C#?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>In a singleton pattern, a class can only have one instance and provides an access point to it globally.<\/p>\n\n\n\n<p>Eg:<\/p>\n\n\n\n<p>Public sealed class Singleton<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>Private static readonly Singleton _instance = new Singleton();<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>49) What is the difference between directcast and ctype?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>DirectCast is used to convert the type of object that requires the run-time type to be the same as the specified type in DirectCast.<\/p>\n\n\n\n<p>Ctype is used for conversion where the conversion is defined between the expression and the type.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>50) Is C# code is managed or unmanaged code?<\/strong><strong><\/strong><\/p>\n\n\n\n<p>C# is managed code because Common language runtime can compile C# code to Intermediate language.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>52) Give an example of removing an element from the queue<\/strong><strong><\/strong><\/p>\n\n\n\n<p>The dequeue method is used to remove an element from the queue.<\/p>\n\n\n\n<p>using System;<\/p>\n\n\n\n<p>using System.Collections;<\/p>\n\n\n\n<p>using System.Collections.Generic;<\/p>\n\n\n\n<p>using System.Linq;<\/p>\n\n\n\n<p>using System.Text;<\/p>\n\n\n\n<p>using System.Threading.Tasks;<\/p>\n\n\n\n<p>namespace DemoApplication<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>&nbsp;class Program<\/p>\n\n\n\n<p>&nbsp;{<\/p>\n\n\n\n<p>&nbsp; static void Main(string[] args)<\/p>\n\n\n\n<p>&nbsp; {<\/p>\n\n\n\n<p>&nbsp;&nbsp; Queue qt = new Queue();<\/p>\n\n\n\n<p>&nbsp;&nbsp; qt.Enqueue(1);<\/p>\n\n\n\n<p>&nbsp;&nbsp; qt.Enqueue(2);<\/p>\n\n\n\n<p>&nbsp;&nbsp; qt.Enqueue(3);<\/p>\n\n\n\n<p>&nbsp;&nbsp; foreach (Object obj in qt)<\/p>\n\n\n\n<p>&nbsp;&nbsp; {<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; Console.WriteLine(obj);<\/p>\n\n\n\n<p>&nbsp;&nbsp; }<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; Console.WriteLine(); Console.WriteLine();<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; Console.WriteLine(&#8220;The number of elements in the Queue &#8221; + qt.Count);<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; Console.WriteLine(&#8220;Does the Queue contain &#8221; + qt.Contains(3));<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; Console.ReadKey();<\/p>\n\n\n\n<p>&nbsp;&nbsp; }<\/p>\n\n\n\n<p>&nbsp;}<\/p>\n\n\n\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C# Interview Questions and Answers Here are C# interview questions and answers for fresher as well 5 or 10 years experienced candidates to get their dream job. 1) What is the role of C#? Sample answer: The role of C# as a programming language is to precisely define a set of operations that a computer [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[12,11,1],"tags":[33,36,34],"class_list":["post-1707","post","type-post","status-publish","format-standard","hentry","category-asp-net","category-csharp","category-uncategorized","tag-net","tag-asp-net","tag-c"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"admin","author_link":"http:\/\/waqar-arshad.com\/index.php\/author\/waqar_29_1\/"},"uagb_comment_info":27,"uagb_excerpt":"C# Interview Questions and Answers Here are C# interview questions and answers for fresher as well 5 or 10 years experienced candidates to get their dream job. 1) What is the role of C#? Sample answer: The role of C# as a programming language is to precisely define a set of operations that a computer&hellip;","_links":{"self":[{"href":"http:\/\/waqar-arshad.com\/index.php\/wp-json\/wp\/v2\/posts\/1707","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/waqar-arshad.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/waqar-arshad.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/waqar-arshad.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/waqar-arshad.com\/index.php\/wp-json\/wp\/v2\/comments?post=1707"}],"version-history":[{"count":1,"href":"http:\/\/waqar-arshad.com\/index.php\/wp-json\/wp\/v2\/posts\/1707\/revisions"}],"predecessor-version":[{"id":1709,"href":"http:\/\/waqar-arshad.com\/index.php\/wp-json\/wp\/v2\/posts\/1707\/revisions\/1709"}],"wp:attachment":[{"href":"http:\/\/waqar-arshad.com\/index.php\/wp-json\/wp\/v2\/media?parent=1707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/waqar-arshad.com\/index.php\/wp-json\/wp\/v2\/categories?post=1707"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/waqar-arshad.com\/index.php\/wp-json\/wp\/v2\/tags?post=1707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}