C# 面试题

C# 高级 面试题 阅读详情


http://career.guru99.com/top-50-c-sharp-interview-questions-answers/


3. Can multiple catch blocks be executed?

No, Multiple catch blocks can’t 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.

4. What is the difference between public, static and void?

All these are access modifiers in C#. 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. 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.


6. Define Constructors?  

A constructor is a member function in a class that has the same name as its class. The constructor is automatically invoked whenever an object class is created. It constructs the values of data members while initializing the class.

7. What is Jagged Arrays?

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 Array of arrays.

8. What is the difference between ref & out parameters?

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.

9. What is the use of using statement in C#?  

The using block is used to obtain a resource and use it and then automatically dispose of when the execution of block completed.

10. What is serialization?  

When we want to transport an object through network then we have to convert the object into a stream of bytes. The process of converting an object into a stream of bytes is called Serialization. For an object to be serializable, it should inherit ISerialize Interface.
De-serialization is the reverse process of creating an object from a stream of bytes.

11. Can “this” be used within a static method?  

We can’t use ‘This’ in a static method because we can only use static variables/methods in a static method.

12. What is difference between constants and read-only?  

Constant variables are declared and initialized at compile time. The value can’t be changed after wards. Read-only variables will be initialized only from the Static constructor of the class. Read only is used only when we want to assign the value at run time.

13. What is an interface class?  

Interface is an abstract class which has only public abstract methods and the methods only have the declaration and not the definition. These abstract methods must be implemented in the inherited classes.

15. What are Custom Control and User Control?  

Custom Controls are controls generated as compiled code (Dlls), those are easier to use and can be added to toolbox. Developers can drag and drop controls to their web forms. Attributes can be set at design time. We can easily add custom controls to Multiple Applications (If Shared Dlls), If they are private then we can copy to dll to bin directory of web application and then add reference and can use them.
User Controls are very much similar to ASP include files, and are easy to create. User controls can’t be placed in the toolbox and dragged – dropped from it. They have their design and code behind. The file extension for user controls is ascx.

16. What are sealed classes in C#?  

We create sealed classes when we want to restrict the class to be inherited. Sealed modifier used to prevent derivation from a class. If we forcefully specify a sealed class as base class then a compile-time error occurs.

17. What is method overloading?  

Method overloading is creating multiple methods with the same name with unique signatures in the same class. When we compile, the compiler uses overload resolution to determine the specific method to be invoke.

18. What is the difference between Array and Arraylist?  

In an array, we can have items of the same type only. The size of the array is fixed. An arraylist is similar to an array but it doesn’t have a fixed size.

19. Can a private virtual method be overridden?  

No, because they are not accessible outside the class.

20. Describe the accessibility modifier “protected internal”.

Protected Internal variables/methods are accessible within the same assembly and also from the classes that are derived from this parent class.

21. What are the differences between System.String and System.Text.StringBuilder classes?

System.String is immutable. When we modify the value of a string variable then a new memory is allocated to the new value and the previous memory allocation released. System.StringBuilder was designed to have concept of a mutable string where a variety of operations can be performed without allocation separate memory location for the modified string.

22. What’s the difference between the System.Array.CopyTo() and System.Array.Clone() ?

Using Clone() method, we creates a new array object containing all the elements in the original array and using CopyTo() method, all the elements of existing array copies into another existing array. Both the methods perform a shallow copy.

23. How can we sort the elements of the array in descending order?

Using Sort() methods followed by Reverse() method.

25.   What’s the difference between an interface and abstract class?

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.


26. What is the difference between Finalize() and Dispose() methods?

Dispose() is called when we want for an object to release any unmanaged resources with them. On the other hand Finalize() is used for the same purpose but it doesn’t assure the garbage collection of an object.

27. What are circular references?

Circular reference is situation in which two or more resources are interdependent on each other causes the lock condition and make the resources unusable.

28. What are generics in C#.NET?

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.

29. What is an object pool in .NET?

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.

30. List down the commonly used types of exceptions in .Net?

ArgumentException, ArgumentNullException , ArgumentOutOfRangeException, ArithmeticException, DivideByZeroException ,OverflowException , IndexOutOfRangeException ,InvalidCastException ,InvalidOperationException , IOEndOfStreamException , NullReferenceException , OutOfMemoryException , StackOverflowException etc.

31. What are Custom Exceptions?

Sometimes there are some errors that need to be handeled as per user requirements. Custom exceptions are used for them and are used defined exceptions.

32. What are delegates?

Delegates are same are function pointers in C++ but the only difference is that they are type safe unlike function pointers. Delegates are required because they can be used to write much more generic type safe functions.

33. How do you inherit a class into other class in C#?

Colon is used as inheritance operator in C#. Just place a colon and then the class name.

public class DerivedClass : BaseClass

 

34. What is the base class in .net from which all the classes are derived from?

System.Object

35. What is the difference between method overriding and method overloading?

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.

36. What are the different ways a method can be overloaded?

Methods can be overloaded using different data types for parameter, different order of parameters, and different number of parameters.

37. Why can’t you specify the accessibility modifier for methods inside the interface?

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’s why they all are public.

38. How can we set class to be inherited, but prevent the method from being over-ridden?

Declare the class as public and make the method sealed to prevent it from being overridden.

39. What happens if the inherited interfaces have conflicting method names?

Implement is up to you as the method is inside your own class. There might be problem when the methods from different interfaces expect different data, but as far as compiler cares you’re okay.

40. What is the difference between a Struct and a Class?

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.

41. How to use nullable types in .Net?

Value types can take either their normal values or a null value. Such types are called nullable types.

Int? someID = null;
If(someID.HasVAlue)
{
}

 

42. How we can create an array with non-default values?

We can create an array with non-default values using Enumerable.Repeat.

43. What is difference between is and as operators in c#?

“is” operator is used to check the compatibility of an object with a given type and it returns the result as Boolean.

“as” operator is used for casting of object to a type or a class.

44. What’s a multicast delegate?

A delegate having multiple handlers assigned to it is called multicast delegate. Each handler is assigned to a method.

 45. What are indexers in C# .NET?

Indexers are known as smart arrays in C#. It allows the instances of a class to be indexed in the same way as array.

Eg:

public int this[int index]    // Indexer declaration

 

46. What is difference between the “throw” and “throw ex” in .NET?

“Throw” statement preserves original error stack whereas “throw ex” have the stack trace from their throw point. It is always advised to use “throw” because it provides more accurate error information.

47. What are C# attributes and its significance?

C# provides developers a way to define declarative tags on certain entities eg. Class, method etc. are called attributes. The attribute’s information can be retrieved at runtime using Reflection.

48. How to implement singleton design pattern in C#?

In singleton pattern, a class can only have one instance and provides access point to it globally.

Eg:

Public sealed class Singleton
{
Private static readonly Singleton _instance = new Singleton();
}

 

49. What is the difference between directcast and ctype?

DirectCast is used to convert the type of an object that requires the run-time type to be the same as the specified type in DirectCast.

Ctype is used for conversion where the conversion is defined between the expression and the type.

50. Is C# code is managed or unmanaged code?

C# is managed code because Common language runtime can compile C# code to Intermediate language.


C#笔试题面试题锦集 .NET面试题 简述 private、 protected、 public、 internal 修饰符的访问权限。 答 . private : 私有成员, 在类的内部才可以访问。 protected : 保护成员,该类内部和继承类中可以访问。 public : 公共成员,完全公开,没有访问限制。 internal: 在同一命名空间内可以访问。 2 .列举ASP.NET 页面之间传递值的几种方式。 答. 1.使用QueryString, 如…?id=1; response. R 阅读详情

相关推荐

c#基础面试题(一)

1. C#是什么?有什么特点 C#是专门为.NET设计的面向Internet和企业级应用的新一代编程语言; 特点: 语言简单;类型安全;完全面向对象 2. 简要比较C#是C++的不同? 它是C++的更新换代产品,提高了开发人员的工作效率,增强了安全性 原因:一、C#限制使用本地指针;二、自动垃圾回收机制; 3. 什么是程序?什么是指令? 程序是指令的有序集合; 指令是指定进行某种

wujiaolong的专栏 926

Java How to Program学习笔记_第十七章_Java SE 8 Lambda及Stream——章节小结(Summary)

第一次正式学习Java的Lambda编程,感觉并不陌生,在Spotfire,PL/SQL, C语言、Excel等很多地方都用过函数式编程。 Summary Section 17.1 Introduction • Prior to Java SE 8, Java supported three programming paradigms—procedural program...

预见未来to50的专栏 1092

一分钟学会MATLAB-数据清洗(含完整代码)

数据清洗是数据分析过程中的一个重要步骤,目的是提高数据的质量,以便进行更有效的分析。% 删除超出阈值的行。% 用线性插值填充缺失值。% 删除包含缺失值的行。% 找到缺失值的位置。% 可视化数据,识别异常值。缺失值是数据清洗中常见的问题。通过以上步骤,你可以有效地清洗数据,使其准备好进行后续的分析和建模。

2402_87132195的博客 3323

使用stream报错:stream has already been operated upon or closed

使用stream流时,编译报错:stream has already been operated upon or closed

LP'S Blog 1736

低代码Agent开发框架使用指南(二)—Coze平台核心功能概览

本篇分享系统介绍了字节跳动推出的低代码智能体开发平台Coze。Coze以免费易用、多模型支持和便捷的跨平台发布为核心优势,显著降低了智能体开发门槛。文章详细解析了平台的六大核心功能:扩展能力边界的插件系统、增强认知的知识库、结构化数据管理的数据库、可视化图像处理的图像流、实现复杂逻辑编排的工作流,以及处理复杂任务的多智能体协作机制,全面展现了Coze平台的强大能力。

weixin_42782643的博客 1365

【Allegro学习笔记】常规标贴封装创建-0402封装创建实例

摘要 本文主要介绍如何使用Allegro制作表面贴装封装。 所使用的软件 使用Allegro制作常规贴片封装主要使用的软件有Pad Designer和Allegro 1 0402类封装制作 1.1 0402类封装焊盘分析 0402封装尺寸图如图1...

Honglong 1万+

C# 温故而知新:Stream篇(五)

C# 温故而知新:Stream篇(五) MemoryStream 目录: 1 简单介绍一下MemoryStream 2 MemoryStream和FileStream的区别 3 通过部分源码深入了解下MemoryStream 4 分析MemorySteam最常见的OutOfMemory异常 5 MemoryStream 的构造 6 MemoryStream 的属性 7 Memor...

weixin_30736301的博客 586

运放偏置电路设计:如何精准计算差分放大器的电压偏移量

本文深入解析了差分放大器偏置电路的设计原理与精准计算方法,重点阐述了如何通过引入参考电压实现信号电压偏移,以适应单电源ADC的输入范围。文章结合实战案例,详细推导了偏移电压公式,并强调了电阻匹配、运放选型及PCB布局对精度和共模抑制比的关键影响,帮助硬件工程师避免常见设计陷阱。

weixin_29288313的博客 642

StreamWriter出现下面错误“正由另一进程使用,因此该进程无法访问该文件”

出现下面错误“正由另一进程使用,因此该进程无法访问该文件” 代码如下 if (!Directory.Exists(Server.MapPath("~//Logs")))         {             Directory.CreateDirectory(Server.MapPath("~//Logs"));         }                    StreamWrit

bingtingabc的专栏 1万+

SAP系统中PP模块全配置文档

配置路径IMG>SAP NetWeaver>常规设置>维护日历>工厂日历事务代码SCAL要求传输工厂代码描述日历代码日历描述起始日期星期一星期二星期三星期四星期五星期六星期日有效开始日期有效结束日期1000南微医学工厂MT南微医学工厂日历√√√√√√√201820502.4定义工厂配置路径IMG>生产>物料清单>常规数据>定义BOM状态事务代码OS23要求传输配置路径IMG>生产>主数据>资源>常规数据>标准值>定义参数。

yanzibing99的博客 1902

Codesys 3.5报警功能配置保姆级教程:从变量定义到确认方式(含REF/ACK详解)

本文详细介绍了Codesys 3.5报警功能的配置流程,从变量定义到确认方式的选择,特别解析了REF和ACK两种确认方式的底层逻辑。通过实战案例和代码示例,帮助工程师快速掌握报警系统的搭建与调试技巧,提升工业自动化项目的可靠性。

weixin_29245767的博客 465

C# Stream使用的相关问题

C# Stream使用的相关问题

820

【编译原理】LL(1)分析方法 生成语法树(c++实现)

基本流程 输入文法->消除左递归->提取左公共因子->求FIRST集->求FOLLOW集->LL(1)分析表->表驱动的预测语法分析过程->输出语法分析结果和语法树

qq_43417265的博客 1万+

C#面试题

C#面试题 C#面试题链接

CC_MyDream的博客 2121

2026最新openclaw(clawbot/moltbot)真正在自己个人电脑上搭建部署,配置飞书远程远程让AI助理操控电脑完成任务,以及结合ollama无限token实现7*24小时工作(附配置)

2026最新openclaw(clawbot/moltbot)真正在自己个人电脑上搭建部署,配置飞书远程远程让AI助理操控电脑完成任务,以及结合 ollama 无限token实现7*24小时工作,以及部署安装需要的 skills 完成复杂的工作任务(附完整可以运行的配置文件)。 很多人已经会配置安装 openclaw 了 ,但是 安装完成之后真正让电脑自动运行起来的很好,完成出色工作的更少,最常见的就是聊聊天,或者执行一些简单的命令,理解要让电脑自动化工作,openclaw、skills、大模型这三样。

代码讲故事 2969

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

C# 100道面试题

C#经典面试题100道 .NET和C#有什么区别 答:.NET一般指 .NET FrameWork框架,它是一种平台,一种技术。 C#是一种编程语言,可以基于.NET平台的应用。 2.一列数的规则如下: 1、1、2、3、5、8、13、21、34… 求第30位数是多少,用递归算法实现。 答:public class MainClass { public static void Main() { ...

lisuyan0的博客 1338

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Unity中关于c#的中级面试题

Unity开发常见问题解析摘要 本文总结了Unity引擎开发中的15个核心知识点: MonoBehaviour生命周期方法(Awake/Update/FixedUpdate等)的执行顺序与用途 委托与事件的差异及安全机制 GC优化策略(对象池/值类型优先) 协程与线程的本质区别 接口与抽象类的特性对比 对象池的实现原理与代码示例 泛型在类型安全与代码复用中的作用 序列化机制与自定义实现 异步资源加载的实践方案 LINQ查询语法与常用操作 跨场景数据传递的多种方式 值类型与引用类型的内存差异 网络多人游戏的实

分享知识,拥抱变化 1211

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

100道C#高频经典面试题带解析答案——全面C#知识点总结

C#(发音为C Sharp)是一种由微软开发的现代、通用、面向对象的编程语言,作为.NET框架的一部分,主要用于开发Windows应用、Web应用、移动应用等。面向对象:支持类、对象、继承、多态、封装等面向对象的特性。类型安全:强类型语言,提供类型检查,减少运行时错误。丰富的类库:提供大量的标准库,简化开发。跨平台:通过.NET Core和.NET 5/6等实现跨平台开发。异步编程:内置支持异步编程模型(async/await),提高应用性能。垃圾回收:自动内存管理,减少内存泄漏和错误。

编程技术探索者,分享C/C++、C#、Java、数据库等开发经验,聚焦实战技巧与AI兴趣,助力编程爱好者成长。 8221

【C#】Unity、C#面试题整理

1.C#中类是否支持多继承?请说明原因。 答:不支持,需要用接口来实现多继承 2.我们都知道一个类可以有多个构造函数,并且C#会在我们创建类的时候默认的提供一个无参的构造函数,当我实现了另外一个有参数的构造函数的时候,我还能调用无参数的构造函数吗?请说明原因。 答:不能,因为一旦你实现了一个构造函数,C#就不会再提供默认的构造函数了,所以需要自己手动写入一个无参数的构造函数。

Zok93 4万+

C# 比较常见的面试题

文章转载自:https://blog.csdn.net/sinat_20559947/article/details/48825209 1.C#中类是否支持多继承?请说明原因。 答:不支持,需要用接口来实现多继承 2.我们都知道一个类可以有多个构造函数,并且C#会在我们创建类的时候默认的提供一个无参的构造函数,当我实现了另外一个有参数的构造函数的时候,我还能调用无参数的构造函数吗?请说明原因。...

u012408847的博客 2万+

Unity 面试题汇总(一)之C#基础

目录 1.重载和重写的区别 2.面向对象的三大特点 3.简述值类型和引用类型有什么区别 4.请简述private,public,protected,internal的区别 5.C#中所有引用类型的基类是什么 6.请简述ArrayList和 List的主要区别 7.请简述GC(垃圾回收)产生的原因,并描述如何避免? 8.请描述Interface与抽象类之间的不同 9.请简述关键...

仙魁XAN 7735

C# 上位机面试题

记录一些上位机面试题,各位面试的时候遇到新的面试题可以私信我或者发在评论区,我会向文档中添加

Saul的博客 4789

C# 常见技术面试题

C# 常见技术面试题 C# 常见技术面试题 https://www.cnblogs.com/hegezhishouzhetian/articles/9295920.html

User_ID002的博客 201

C#常见面试题

Task较新,发布于.NET 4.5,能结合新的async/await代码模型写代码,它不止能创建新线程,还能使用线程池(默认)、单线程等方式编程,在UI编程领域,Task还能自动返回UI线程上下文,还提供了许多便利API以管理多个Task。在多线程环境下,多个线程可能同时访问和修改共享的数据,如果操作不是原子性的,就可能出现竞争条件(race condition),导致数据不一致或错误的结果。减小锁的范围:只在必要的代码块内使用锁,避免锁的范围过大,从而降低锁的竞争和线程等待时间。

weixin_43807909的博客 489

130道C#面试题

下边是微软软件开发培训讲师李建忠老师对C#编程语言进行的几个层次划分。 不妨对照,你的C#开发水平介于下边C#语言的哪几个层次。 C#语言的几个层次 不谈具体领域(比如搜索,视频,网络等),单就C#编程语言这个垂直方向,我大体上对它有一个如下的层次划分。   1. 基本运用C#语法,在各种工具和示例代码的支持下,完成一些基本程序任务   2. 熟练掌握面向对象与组件构造,知其然亦知其

SzMing 689

C#面试题系列--动态更新

C#面试题系列--动态更新

Blue 1972
上一篇: 用户控件和自定义控件的区别
下一篇: Finalize、Dispose、Close 的区别与使用
令羽飞飞
博客等级 码龄14年 42粉丝 166原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值