做个一套C#面试题

1.int long float double 分别是几个字节

左到右范围从小到大:byte->short->int->long->float->double

各自所占字节大小:1字节、2字节、4字节、8字节、4字节、8字节

2.System.Object四个公共方法的申明

namespace System
{
    //
    // 摘要:
    //     Supports all classes in the .NET class hierarchy and provides low-level services
    //     to derived classes. This is the ultimate base class of all .NET classes; it is
    //     the root of the type hierarchy.
    public class Object
    {
        //
        // 摘要:
        //     Initializes a new instance of the System.Object class.
        public Object();

        //
        // 摘要:
        //     Allows an object to try to free resources and perform other cleanup operations
        //     before it is reclaimed by garbage collection.
        ~Object();

        //
        // 摘要:
        //     Determines whether the specified object instances are considered equal.
        //
        // 参数:
        //   objA:
        //     The first object to compare.
        //
        //   objB:
        //     The second object to compare.
        //
        // 返回结果:
        //     true if the objects are considered equal; otherwise, false. If both objA and
        //     objB are null, the method returns true.
        public static bool Equals(Object? objA, Object? objB);
        //
        // 摘要:
        //     Determines whether the specified System.Object instances are the same instance.
        //
        // 参数:
        //   objA:
        //     The first object to compare.
        //
        //   objB:
        //     The second object to compare.
        //
        // 返回结果:
        //     true if objA is the same instance as objB or if both are null; otherwise, false.
        public static bool ReferenceEquals(Object? objA, Object? objB);
        //
        // 摘要:
        //     Determines whether the specified object is equal to the current object.
        //
        // 参数:
        //   obj:
        //     The object to compare with the current object.
        //
        // 返回结果:
        //     true if the specified object is equal to the current object; otherwise, false.
        public virtual bool Equals(Object? obj);
        //
        // 摘要:
        //     Serves as the default hash function.
        //
        // 返回结果:
        //     A hash code for the current object.
        public virtual int GetHashCode();
        //
        // 摘要:
        //     Gets the System.Type of the current instance.
        //
        // 返回结果:
        //     The exact runtime type of the current instance.
        public Type GetType();
        //
        // 摘要:
        //     Returns a string that represents the current object.
        //
        // 返回结果:
        //     A string that represents the current object.
        public virtual string? ToString();
        //
        // 摘要:
        //     Creates a shallow copy of the current System.Object.
        //
        // 返回结果:
        //     A shallow copy of the current System.Object.
        protected Object MemberwiseClone();
    }
}

3.自定义类型在什么情况下需要override Equals函数?为什么往往需要同时Override GetHashCode

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值