為了學習值型別,看了一下.NET CORE原始碼里的INT定義
[Serializable]
[StructLayout(LayoutKind.Sequential)]
[TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public readonly struct Int16 : IComparable, IConvertible, IFormattable, IComparable<short>, IEquatable<short>, ISpanFormattable
{
private readonly short m_value; // Do not rename (binary serialization)
public const short MaxValue = (short)0x7FFF;
public const short MinValue = unchecked((short)0x8000);
// Compares this object to another object, returning an integer that
// indicates the relationship.
// Returns a value less than zero if this object
// null is considered to be less than any instance.
// If object is not of type Int16, this method throws an ArgumentException.
//
public int CompareTo(object? value)
{
if (value == null)
{
return 1;
}
if (value is short)
{
return m_value - ((short)value).m_value;
}
throw new ArgumentException(SR.Arg_MustBeInt16);
}
public int CompareTo(short value)
{
return m_value - value;
}
public override bool Equals([NotNullWhen(true)] object? obj)
{
if (!(obj is short))
{
return false;
}
return m_value == ((short)obj).m_value;
}
m_value 這個變數沒有賦值,如何進行操作呢。
另外就是傳入的都是short型別
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/266871.html
標籤:C#
上一篇:https下的POST請求
下一篇:請教一個listview的問題
