前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >.NET面试基础知识

.NET面试基础知识

作者头像
程序你好
发布2018-09-29 11:23:39
8120
发布2018-09-29 11:23:39
举报
文章被收录于专栏:程序你好程序你好

本文将介绍关于.Net basic的非常有限的概念。

主题

  • Access level of access modifiers
  • Access modifiers for types and type members
  • Default access modifier for class and its members
  • IEnumerable vs. IEnumerator
  • IEnumerable vs. IQueryable
  • Single method interface as IComparable vs. IComparer
  • Variable declared as const vs. readOnly
  • Default value expressions
  • Passing parameters to methods and return value
  • ref return values and ref locals
  • Sealed class and sealed method
  • EF Core development approaches
  • Compile-time vs. run-time polymorphism
  • Abstract method vs. virtual method
  • Abstract class vs. interface
  • Application domain
  • Serialization vs. deserialization
  • Use of stream
  • Http post vs. put
  • Process vs. thread
  • The mechanisms to run code in parallel
  • Synchronization mechanisms in threads

职位和职责

不同公司的职位和工作职责不同。在面试中,工作职责和经验对这个职位很重要。程序员职位有一年的经验他们会关注oops概念、并行编程、算法和解决问题的能力等等。另一方面,如果这个职位需要夫妻几年经验之后,他们可以专注于最新的框架、语言及其特点,单元测试概念、场景基础问题,软件开发方法,设计原则,设计模式,最佳实践指导方针和软件架构等。

深入了解.net的基本概念

访问级别的访问修饰符

Private访问限制在包含它的类中。在下面的图中,privateA只能在ClassA中访问,其他类无法访问它。

Protected

可以在包含类中访问,也可以访问从该类派生的所有类。例如,classA的ProtectedB可以在包含的classA内部访问,也可以从assembly - a中的派生类ClassB访问。它也可以从另一个assembly - b中的派生类类类类中访问。

Note不要仅仅关注访问修饰符和类之间的关系来判断不同的类图。

Internal对同一程序集中声明的所有类都可访问。例如,ClassA的InternlC可以在包含类ClassA的内部访问,也可以被任何类ClassB和class .ses访问在同一个汇编程序集中。

Private protected (C# 7.2)可由同一程序集中的任何派生类访问。例如,classA的PrivateProtectedD可以在包含类classA的内部访问,也可以从汇编- a中的派生类classB访问。

Protected internal可访问同一程序集中声明的所有类或从另一个程序集中的派生类中声明的所有类。例如,ClassA的ProtectedInternalE可以从同一程序集a中的所有类ClassA、ClassB和ClassC访问,也可以从另一个程序集b中的派生类类类访问。

Public

由任何人访问。例如,可以从程序集a或程序集b中的所有类访问ClassA的PublicF。

类型和类型成员的访问修饰符,

类型(类、结构、枚举、接口、委托等)只能有内部和公共访问修饰符。

类型成员(字段、属性、构造函数、方法等)可以拥有所有的访问修饰符。

类及其成员的默认访问修饰符

如果没有指定访问修饰符,

内部是类的默认值,

成员默认为private。

IEnumerable vs. IEnumerator

这些都是向前使用的,并且只读取一个集合的访问权限。

  • IEnumerable使用IEnumerator,它可以与foreach语句一起使用。
  • IEnumerator有MoveNext、重置方法和当前属性。它可以与while语句一起使用。
    1. List < string > stringList = new List < string > () {
    2. "Rony",
    3. "Anna",
    4. "Jhon"
    5. };
    6. //// IEnumerator
    7. Console.WriteLine("IEnumerator:n");
    8. IEnumerator < string > enumeratorStringList = stringList.GetEnumerator();
    9. while (enumeratorStringList.MoveNext()) {
    10. Console.WriteLine(enumeratorStringList.Current);
    11. }
    12. //// IEnumerable
    13. Console.WriteLine("nIEnumerable:n");
    14. IEnumerable < string > enumerableStringList = stringList;
    15. foreach(string item in enumerableStringList) {
    16. Console.WriteLine(item);
    17. }

IEnumerable vs. IQueryable

们都可以用于向前数据访问。

IEnumerable

  • 以从内存集合中查询数据(比如,列表)
  • 它在内存中加载数据(服务器端到客户端),同时从数据库查询数据,然后过滤客户端数据。
  • 不支持自定义查询。
  • 不支持延迟加载。
  • 适合于LINQ-to-Object或LINQ-to-XML。

IQueryable

可以从内存之外查询数据(服务器端类、远程数据库、web服务)

它在数据库查询时过滤服务器端的数据,然后发送到客户端。它提高了性能。

支持自定义查询(CreateQuery, Execute方法)。

支持延迟加载。

linq to sql

IComparable vs. IComparer

它们都可以用于集合中的自定义排序。主要的区别是 IComparable允许内部排序实现,而IComparer允许外部定制排序实现。

IComparable

IComparer

IComparer using lambda expression,

  1. personObjList.Sort((x, y) => x.Name.CompareTo(y.Name));
  2. personObjList.Sort((x, y) => x.Age.CompareTo(y.Age));

IComparer on multiple properties in the class,

  1. public class PersonComparer: IComparer < Person > {
  2. public enum SortBy {
  3. FirstName,
  4. Age
  5. }
  6. private SortBy sortBy;
  7. public PersonComparer(SortBy sortBy) {
  8. this.sortBy = sortBy;
  9. }
  10. public int Compare(Person x, Person y) {
  11. switch (this.sortBy) {
  12. case SortBy.FirstName:
  13. return x.FirstName.CompareTo(y.FirstName);
  14. case SortBy.Age:
  15. return x.Age.CompareTo(y.Age);
  16. default:
  17. return x.FirstName.CompareTo(y.FirstName);
  18. }
  19. }
  20. }
  21. //// How to use PersonComparer
  22. personObjList.Sort(new PersonComparer(PersonComparer.SortBy.Age));
  23. //// personObjList.Sort(new PersonComparer(PersonComparer.SortBy.FirstName));

变量声明为const vs. readOnly

Const

Const是在声明时初始化的。否则,它将抛出编译错误。它被称为编译时常数。它不能在运行时更改。默认情况下,它是静态的。ReadOnly

它可以在声明时初始化,也可以在同一个类的构造函数中多次设置。它被称为运行时常数。

Default value expressions

Passing parameters to methods and return value

  • ref uses to pass variable for input and output; It is initialized before passing.
  • in (C# 7.2) uses to pass variable only for input; It is initialized before passing.
  • out uses only for output; It is initialized inside method.

Example

  1. internal class ParameterPassing {
  2. public void ParameterPassingExample(int valueA, ref int inputAndOutputValueB, in int inputOnlyValueC, out int outputOnlyValueD) {
  3. inputAndOutputValueB = valueA + inputAndOutputValueB;
  4. outputOnlyValueD = inputAndOutputValueB + inputOnlyValueC;
  5. }
  6. }
  7. static void Main(string[] args) {
  8. ////******************* Call *********************////
  9. int valueA = 5;
  10. int inputAndOutputValueB = 6;
  11. int inputOnlyValueC = 7;
  12. int outputOnlyValueD;
  13. ParameterPassing parameterPassing = new ParameterPassing();
  14. parameterPassing.ParameterPassingExample(valueA, ref inputAndOutputValueB, in inputOnlyValueC, out outputOnlyValueD);
  15. }

ref returns on method and ref locals

ref return returns the storage location and ref locals can store that in a local variable. But ref readonly locals(C# 7.2) doesn't allow writes to that object instead of read value.

Sealed Class and sealed method

  • sealed class can't be inherited
  • sealed method can't be override in a derived class

Example of sealed class,

Example of sealed method,

EFcore开发方法

实体框架(EF) Core 2.0不支持DB模型(edmx)的可视化设计器或向导。EF Core只支持两种开发方法,

  • Code-First
  • Database-First.

编译时和运行时多态性

多态性(指一个名称、多个表单)一个接口和多个实现。

绑定/类型的多态性

绑定是方法调用到方法实现的连接。

Compile-time polymorphism (early-binding/overloading/static binding)

Method overloading

同一类中的方法的相同名称采用多种实现形式。

Operator overloading

Run-time polymorphism (late-binding/overriding/dynamic-binding)

It is implemented using inheritance and virtual method.

Abstract method vs. virtual method

  • Virtual method has default implementation as well as provides the derived class with an option of overriding it.
  • Abstract method doesn’t provide default implementation and forces the derived class to override the method.

Abstract class vs. interface

  • Accessibility modifier (public/internal etc.) is allowed for abstract class. Interface doesn't allow accessibility modifier.
  • Class can inherit only one abstract class; class can implement more than one interface.
  • Abstract classes can have default implementations for some of its (virtual) members (methods), but the interface class holds only the signature. It can't have implementation for any of its members. But C# 8(not release yet) supports default implantation of the methods in the interface.Example,

Application domain

应用程序域为安全提供了应用程序的逻辑隔离边界。同一个应用程序的所有对象都在同一个应用程序域中创建。应用程序域在单个进程中保持程序集的独立性。

Serialization vs. deserialization

  • Serialization: Transforming object to XML string.
  • Deserialization: Transforming XML string to object.

More details click here,

Use of stream

当数据量太大时,很难同时将整个数据加载到内存中。流用于从大文件中读取数据。您可以读取小块的数据,其中大文件被分解成小块。

Http post vs. put

  • Post is used to create new entity
  • Put is used to update an existing entity.

Process vs. thread

线程在共享内存空间中运行,而进程在单独的内存空间中运行。

双击Outlook图标,就可以在操作系统中启动应用程序,这是一个过程。流程是应用程序的执行实例。

您可以将“auto spelling & grammar check”和“auto check names”看作是Outlook中的主题。线程是进程内的执行路径。

The mechanisms to run code in parallel

Example of the simple signatures,

Synchronization mechanisms in threads

当多个线程共享资源(共享数据)时,可能会产生问题。生产者-消费者和读者-作者问题是最常见的例子。为了避免这个问题,我们需要同步访问数据。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-09-04,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 程序你好 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档