Skip to content

Instantly share code, notes, and snippets.

@ShineSmile
Last active June 24, 2019 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShineSmile/65893fe01e78c98404b442b22fd5a7e8 to your computer and use it in GitHub Desktop.
Save ShineSmile/65893fe01e78c98404b442b22fd5a7e8 to your computer and use it in GitHub Desktop.
interview questions
  1. 求下述代码片段的输出,并且解释原因
    static void Main()
    {
        var i = 5;
        UpdateValue(i);
        Console.WriteLine(i);
    
        var s = new Student() { Age = 10 };
        UpdateReference(s);
        Console.WriteLine(s.Age);
    
        var rs = new Student() { Age = 10 };
        UpdateReference(ref rs);
        Console.WriteLine(rs.Age);
    
        var t = new Student() { Age = 20 };
        UpdateProperty(t);
        Console.WriteLine(t.Age);
    }
    
    static void UpdateValue(int input)
    {
        input = 10;
    }
    
    static void UpdateReference(Student t)
    {
        t = new Student() { Age = 15 };
    }
    
    static void UpdateReference(ref Student rt)
    {
        rt = new Student() { Age = 15 };
    }
    
    static void UpdateProperty(Student s)
    {
        s.Age = 25;
    }
    
    class Student
    {
        public int Age { get; set; }
    }
  2. 求下述代码片段的输出,并且解释原因
    class Root
    {
        public object o1 = new object();
        public object o2 => new object();
        public object o3()
        {
            return new object();
        }
    }
    
    void Main()
    {
        var a = new Root();
    
        var x = a.o1;
        var y = a.o1;
        Console.WriteLine(ReferenceEquals(x, y));
    
        var i = a.o2;
        var j = a.o2;
        Console.WriteLine(ReferenceEquals(i, j));
    
        var p = a.o3();
        var q = a.o3();
        Console.WriteLine(ReferenceEquals(p, q));
    }
  3. Linq的延迟求值是什么?
  4. 求下述代码片段的输出,并解释原因
    var i = 0;
    var tempList =
      Enumerable.Range(1, 10000)
      .Select(
        item =>
        {
            i += 1;
            return item;
        })
      .Where(t => t % 3 == 0)
      .Take(5);
    Console.WriteLine(i);
  5. HashSet<T>SortedSet<T>在数据结构上的区别
  6. Dictionary<TKey,TValue>中的TKeyTValue是值还是类型,使用时Dictionary<TKey,TValue>Hashtable有什么区别
  7. 协变和逆变是什么?
  8. 如何判断变量储存在栈上还是堆上
  9. 简述CLR垃圾回收策略
  10. 简述async Taskasync Task<T>async void方法之间的区别
    • 相比Thread使用async方法有什么好处
    • 什么情况下会用到async void
    • 如果上述三种异步方法执行过程中有异常产生并抛出,方法外部能不能捕捉到?
  11. 下述语句中,RareResource需要实现什么接口
    using(var x = new RareResource())
    {
        //Use x do something
    }
  12. 简单列举类型推断会失效的情况。
  13. 查阅资料,以Azure Table Storage为例,简述PartitionKeyRowKey的作用,在设计表时和CRUD时需要注意哪些问题
  14. 使用csharp完成下面反转整数的方法。提示:越界产生时返回0
    public int ReverseInteger(int input)
    {
        //Write your code here
    }
@ShineSmile
Copy link
Author

ShineSmile commented Jun 4, 2019

请不要在这里直接回复

请于https://gist.github.com注册、登陆并提交新的文件,并将其地址通过邮箱回复。

谢谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment