【C# Programming】值类型、良构类型

值类型

1、值类型

        值类型的变量直接包含值。换言之, 变量引用的位置就是值内存中实际存储的位置。

2、引用类型

        引用类型的变量存储的是对一个对象实例的引用(通常为内存地址)。

        复制引用类型的值时,复制的只是引用。这个引用非常小(32位机器时4 字节引用)

3、结构

        除string 和object 是引用类型,所有C# 内建类型都是值类型。C#也 允许用户自定义值类型。

        结构是一种自定义的值类型,它使用关键字struct。 例如:

struct Angle
{public Angle(int degrees, int minutes, int seconds){Degrees = degrees;Minutes = minutes;Seconds = seconds;}// Using C# 6.0 read-only, automatically implememted properties.public int Degrees { get; }public int Minutes { get; }public int Seconds { get; }public Angle Move(int degrees, int minutes, int seconds){return new Angle(Degrees + degrees, Minutes + minutes, Seconds + seconds);}
}
3.1 结构的初始化
  • 除了属性和字段,结构还可包含方法和构造器。结构不允许包含用户定义的默认构造器。在没有提供默认的构造器时, C# 编译器会自动生成一个默认构造器将所有字段初始化为各自的默认值。
  • 为了确保值类型的局部变量能完全初始化,结构的每个构造器都必须初始化结构中所有字段。如果对结构的所有数据初始化失败,会造成编译错误。  
  • C# 禁止结构中的字段初始化器,例如:
struct Angle 
{//……// ERROR:  Fields cannot be initialized at declaration time// private int _Degrees = 42;
}
  • 为值类型使用new 操作符,会造成“运行时”在临时存储池中创建对象的新实例,并将所有字段初始化为默认值。

4、default 操作符的使用

        所有值类型都有自定义的无参构造器将值类型的实例初始化成默认状态。所以总可以合法使用new操作符创建值类型的变量。除此之外,还可使用default操作符生成结构的默认值。例如: 

struct Angle
{public Angle(int hours, int minutes): this(hours, minutes, default(int)) {}public Angle(int degrees, int minutes, int seconds){Degrees = degrees;Minutes = minutes;Seconds = seconds;}public int Degrees { get; }public int Minutes { get; }public int Seconds { get; }public Angle Move(int degrees, int minutes, int seconds){return new Angle(Degrees + degrees, Minutes + minutes, Seconds + seconds);}
}

5、值类型的继承和接口

  • 所有值类型都隐式密封
  • 除枚举外,所有值类型都派生自 System.ValueType
  • 值类型也能实现接口

6、装箱

6.1 将值类型转换为一个引用类型称为装箱(boxing) 转换。 转换的结果时对一个存储位置的引用。

转换的步骤如下:

  • 在堆上分配内存, 它将用于存放值类型数据以及少许额外开销。  
  • 接着发生一次内存复制,当前存储位置的值类型数据被复制到堆上分配好的位置。
  • 转换的结果是对堆上新存储位置的引用  
6.2 相反的过程称为拆箱(unboxing).拆箱转换先检查已经装箱的值的类型兼容于要拆箱成的值类型,然后复制堆中存储的值
6.3 装箱/拆箱的CIL 代码

6.4 如果装箱和拆箱进行的不是很频繁,那么实现它们的性能问题不大。但有的时候,装箱会频繁发生,这就可能大幅影响性能。例如:
static void Main()
{int totalCount;System.Collections.ArrayList list = new System.Collections.ArrayList();Console.Write("Enter a number between 2 and 1000:");totalCount = int.Parse(Console.ReadLine());// Execution-time error:// list.Add(0);  // Cast to double or 'D' suffix required. Whether cast or using 'D' suffix, list.Add((double)0);  // boxinglist.Add((double)1);  // boxingfor(int count = 2; count < totalCount; count++){list.Add(((double)list[count - 1] +    // unboxing(double)list[count - 2]));    // unboxing}foreach(double count in list)   // unboxing Console.Write("{0}, ", count);//boxing
}  
6.5 另一个装箱/拆箱例子 (接口要求被调用者为引用类型):
class Program 
{static void  Main(){Angle angle = new Angle(25, 58, 23);object objectAngle = angle;  // BoxConsole.Write(((Angle)objectAngle).Degrees);((Angle)objectAngle).MoveTo(26, 58, 23);   // Unbox, modify unboxed value, and discard valueConsole.Write(", " + ((Angle)objectAngle).Degrees);((IAngle)angle).MoveTo(26, 58, 23);     // Box, modify boxed value, and discard reference to boxConsole.Write(", " + ((Angle)angle).Degrees);((IAngle)objectAngle).MoveTo(26, 58, 23);    // Modify boxed value directlyConsole.WriteLine(", " + ((Angle)objectAngle).Degrees);}
}
interface IAngle 
{void MoveTo(int hours, int minutes, int seconds);
}
struct Angle : IAngle 
{public Angle(int degrees, int minutes, int seconds) {Degrees = degrees;Minutes = minutes;Seconds = seconds;}// NOTE:  This makes Angle mutable, against the general guidelinepublic void MoveTo(int degrees, int minutes, int seconds) {Degrees = degrees;Minutes = minutes;Seconds = seconds;}public int Degrees {get; set;}public int Minutes {get; set;}public int Seconds {get; set;}
}
6.6 如果将值类型的实例作为接收者来调用object 声明的虚方法时
  • 如果接收者已拆箱,而且结构重写了该方法,将直接调用重写的方法。因为所有值类型都是密封的。
  • 如果接收者已拆箱,而且结构没有重写该方法,就必须调用基类的实现。该实现预期的接收者是一个对象引用。所以接收者被装箱。
  • 如果接收者已装箱,而且结构重写了该方法,就将箱子的存储位置传给重写的方法,不对其拆箱。
  • 如果接收者已装箱,而且结构没有重写该方法,就将箱子的引用传给基类的实现,该实现预期正是一个引用。

7、枚举

  • 枚举是由开发者声明的值类型。枚举的关键特征是在编译时声明了一组可以通过名称来引用的常量值。例如:
enum ConnectionState
{Disconnected,Connecting,Connected,Disconnecting
}
  • 想要使用枚举值需要为其附加枚举名称前缀。 例如:ConnectionState. Connecting
  • 枚举值实际是作为整数常量实现的,第一个枚举值默认为0, 后续每项都递增1, 然而可以显式为枚举赋值。例如:
enum ConnectionState : short
{Disconnected,Connecting = 10,Connected,Joined = Connected,Disconnecting
}
  • 所有的枚举基类都是System.enum. 后者从System.ValueType 派生。除此之外,不能从现有枚举类型派生以添加额外成员
  • 对于枚举类型,它的值并不限于限于声明中命名的值。 只要值能转换成基础类型,就能转换枚举值。

8、枚举和字符串之间的转换

  • 枚举的一个好处是ToString() 方法会输出枚举值的标识符。
  • 使用Enum.Parse可以将字符串转换为枚举
public static void Main()
{ThreadPriorityLevel priority = (ThreadPriorityLevel)Enum.Parse(typeof(ThreadPriorityLevel), "Idle");Console.WriteLine(priority);
}
  • 为了避免抛出异常,C#4.0 后提供了TryParse 方法。
public static void  Main()
{System.Diagnostics.ThreadPriorityLevel priority;if(Enum.TryParse("Idle", out priority)){Console.WriteLine(priority);}
}

9、枚举作为标志使用

  • 枚举值还可以组合以表示复合值。 此时,枚举声明应使用 Flags 属性进行标记以表示枚举值可以组合,  例如:
[Flags] 
public enum FileAttributes
{None = 0,                             // 000000000000000ReadOnly = 1 << 0,             // 000000000000001Hidden = 1 << 1,                 // 000000000000010System = 1 << 2,                 // 000000000000100Directory = 1 << 4,             // 000000000010000Archive = 1 << 5,                // 000000000100000Device = 1 << 6,                  // 000000001000000Normal = 1 << 7,                // 000000010000000Temporary = 1 << 8,          // 000000100000000SparseFile = 1 << 9,           // 000001000000000ReparsePoint = 1 << 10,   // 000010000000000Compressed = 1 << 11,    // 000100000000000Offline = 1 << 12,              // 001000000000000NotContentIndexed = 1 << 13,    // 010000000000000Encrypted = 1 << 14,        // 100000000000000
}
  • 可以使用按位OR 操作符联结枚举值,使用按位AND操作符测试特定位是否存在
public static void ChapterMain()
{string fileName = @"enumtest.txt";System.IO.FileInfo file = new System.IO.FileInfo(fileName);file.Attributes = FileAttributes.Hidden | FileAttributes.ReadOnly;Console.WriteLine(“{0} | {1} = {2}”,  FileAttributes.Hidden, FileAttributes.ReadOnly,  (int)file.Attributes);if((file.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)throw new Exception("File is not hidden.");if((file.Attributes & FileAttributes.ReadOnly) != FileAttributes.ReadOnly)throw new Exception("File is not read-only.");
}
  • 枚举声明中也可以用标志组合定义额外的枚举值
[Flags]
enum DistributedChannel
{None = 0,Transacted = 1,Queued = 2,Encrypted = 4,Persisted = 16,FaultTolerant = Transacted | Queued | Persisted
}

良构类型

1、重写ToString

  • 默认情况下,在任何对象上调用ToString() 将返回类的完全限定名称 。例如:在一个Sytem.IO.FileStream对象上调用ToString() 方法将返回字符串 System.IO.FileStream
  • Console.WriteLine() 和System.Diagnostics.Trace.Write 等方法会调用对象的ToString 方法。 因此,重写ToString 输出比默认值更有意义的信息
public struct Coordinate
{public Coordinate(Longitude longitude, Latitude latitude) {Longitude = longitude;Latitude = latitude;}public Longitude Longitude { get; }public Latitude Latitude { get; }public override string ToString() =>$"{ Longitude } { Latitude }";
}
public struct Longitude { }
public struct Latitude { }
  •  由于缺乏本地化和其他高级格式化功能,所以它不太适合一般性用户文本显示

2、重写GetHashCode

        散列码的作用是生成与对象值对应的数字,从而高效地平衡散列表。 为了获得良好的GetHashCode() 的实现,请参照以下原则

  1. 必须:相等的对象必须有相等的散列值。(若a.Equals(b)),则 a.GetHashCode ()== b.GetHashCode()
  2. 必须:在特定对象的生存期内,GetHashCode() 始终返回相同的值,即使对象数据发生了变化。
  3. 必须: GetHashCode() 不应引发任何异常。它总是成功返回一个值
  4. 性能: 散列码应尽可能唯一
  5. 性能: 可能的散列码的值应当尽可能在int 范围内平均分布
  6. 性能: GetHashCode() 的性能应该优化,它通常在Equals 中实现用于“短路”一次完整的相等性比较。所以当类型作为字典集合中的key 使用时,会频繁调用该方法
  7. 性能:两个对象的细微差别应造成散列码的极大差异。 理想情况下,1位的差异应造成散列码平均16位的差异,这有助于保持散列的平衡性
  8. 安全性: 攻击者应该难以伪造具有特定散列值的对象

        在重写Equals或者将类作为散列表集合的键时,需要重写GetHashCode。(如:Collections.HashTable 和 Collections.Generic.Dictionary)

public struct Coordinate
{public Coordinate(Longitude longitude, Latitude latitude){Longitude = longitude;Latitude = latitude;}public Longitude Longitude { get; }public Latitude Latitude { get; }public override int GetHashCode(){int hashCode = Longitude.GetHashCode();// As long as the hash codes are not equalif(Longitude.GetHashCode() != Latitude.GetHashCode()){hashCode ^= Latitude.GetHashCode();  // eXclusive OR}return hashCode;}public override string ToString() => string.Format("{0} {1}", Longitude, Latitude);
}
public struct Longitude { }
public struct Latitude { }

        通常采用的方法是像相关类型的散列码应用XOR 操作符,并确保XOR的操作数不相近或相等。否则结果全为零。在操作数相近或相等的情况下,考虑改为使用移位和加法的操作。

        为了进行更细致的控制,应该使用移位操作符来分解比int 大的类型。 例如,对于一个名为value 的long类型,int GetHashCode() {return ((int)value ^ (int)(value >>32))} ;

        如果基类不是object, 应该在XOR 赋值中包含base.GetHashCode()

        假如计算得到的值可能改变,或者哉将值缓存之后能显著优化性能,就应该对散列值进行缓存。

3、重写Equals

对象同一性 和相等的对象值

  • 两个引用如果引用同一个对象,就说它们是同一的。object 包含名为ReferenceEquals() 的静态方法,它能显式检查对象的同一性
  • 两个对象实例的成员值部分或全部相等,也可以说它们相等      

实现Equals  

  1. 检查是否为null  
  2. 如果是引用类型,就检查引用是否相等
  3. 检查数据类型是否相同
  4. 一个指定了具体类型的辅助方法,它能将操作数视为要比较的类型,而不是将其视为对象
  5. 可能要检查散列码是否相等。  
  6. 如果基类重写了Equals,就检查base.Equals()
  7. 比较每一个标识字段,判断是否相等
  8. 重写GetHashCode
  9. 重写== 和!= 操作符

重写Equals 例子:

//例1:
public sealed class ProductSerialNumber
{public ProductSerialNumber(string productSeries, int model, long id){ProductSeries = productSeries;Model = model;Id = id;}public string ProductSeries { get; }public int Model { get; }public long Id { get; }public override int GetHashCode(){int hashCode = ProductSeries.GetHashCode();hashCode ^= Model;  // Xor (eXclusive OR)hashCode ^= Id.GetHashCode();  // Xor (eXclusive OR)return hashCode;}public override bool Equals(object obj){if(obj == null )return false;if(ReferenceEquals(this, obj))return true;if(this.GetType() != obj.GetType())return false;return Equals((ProductSerialNumber)obj);}        public bool Equals(ProductSerialNumber obj){return ((obj != null) && (ProductSeries == obj.ProductSeries) &&(Model == obj.Model) && (Id == obj.Id));}//....        
}//例2:
public static void Main()
{ProductSerialNumber serialNumber1 =new ProductSerialNumber("PV", 1000, 09187234);ProductSerialNumber serialNumber2 = serialNumber1;ProductSerialNumber serialNumber3 =  new ProductSerialNumber("PV", 1000, 09187234);// These serial numbers ARE the same object identity.if(!ProductSerialNumber.ReferenceEquals(serialNumber1, serialNumber2))throw new Exception("serialNumber1 does NOT " + "reference equal serialNumber2");// And, therefore, they are equal.else if(!serialNumber1.Equals(serialNumber2))throw new Exception("serialNumber1 does NOT equal serialNumber2");else {Console.WriteLine("serialNumber1 reference equals serialNumber2");Console.WriteLine("serialNumber1 equals serialNumber2");}// These serial numbers are NOT the same object identity.if(ProductSerialNumber.ReferenceEquals(serialNumber1, serialNumber3))throw new Exception("serialNumber1 DOES reference " +  "equal serialNumber3");// But they are equal (assuming Equals is overloaded).else if(!serialNumber1.Equals(serialNumber3) ||  serialNumber1 != serialNumber3)throw new Exception("serialNumber1 does NOT equal serialNumber3");Console.WriteLine("serialNumber1 equals serialNumber3");
}

4、比较操作符重载

        实现操作符的过程称为操作符重载. C# 支持重载所有操作符,除了x.y、 f(x)、 new、 typeof、default、checked、unchecked、delegate、is、as、= 和=> 之外    

        一旦重写了Equals, 就可能出现不一致情况,对两个对象执行Equals()可能返回true,但 ==操作符返回false. 因为==默认也是执行引用相等性检查。因此需要重载相等(==)和不相等操作符(!=)  

public sealed class ProductSerialNumber
{//... public static bool operator ==(ProductSerialNumber leftHandSide, ProductSerialNumber rightHandSide){// Check if leftHandSide is null.   (operator== would be recursive)if(ReferenceEquals(leftHandSide, null)){return ReferenceEquals(rightHandSide, null);  // Return true if rightHandSide is also nulland false otherwise.}return (leftHandSide.Equals(rightHandSide));}public static bool operator !=(ProductSerialNumber leftHandSide, ProductSerialNumber rightHandSide){return !(leftHandSide == rightHandSide);}
}

5、二元操作符重载

        +、-、* 、/ 、%、|、^、<<和>> 操作符都被实现为二元静态方法。其中至少一个参数的类型是包容类型。方法名由operator 加操作名构成。 

public struct Arc
{public Arc(Longitude longitudeDifference, Latitude latitudeDifference){LongitudeDifference = longitudeDifference;LatitudeDifference = latitudeDifference;}public Longitude LongitudeDifference { get; }public Latitude LatitudeDifference { get; }
}
public struct Coordinate
{//....public static Coordinate operator +(Coordinate source, Arc arc){Coordinate result = new Coordinate(   new Longitude(  source.Longitude + arc.LongitudeDifference),new Latitude(source.Latitude + arc.LatitudeDifference));return result;}
}

6、 赋值与二元操作符的结合

        只要重载了二元操作符,就自动重载了赋值操作符和二元操作符的结合(+=、-=、/=、%=、&=、|=、^=、<<=和>>=. 所以可以直接使用下列代码     coordinate += arc;  

        它等价于:     coordinate = coordinate + arc;

7、一元操作符

  • 一元操作符的重载类似于二元操作符的重载,只是它们只获取一个参数 该参数必须是包容类型。
public struct Latitude
{//……// UNARYpublic static Latitude operator -(Latitude latitude){return new Latitude(-latitude.Degrees);}public static Latitude operator +(Latitude latitude){return latitude;}
}
  • 重载 true 和 false 时,必须同时重载两个操作符。它们的签名和其他操作符重载必须相同,但是返回值必须时一个bool 值。
public struct Example
{//public static bool operator false(object item)//{//    return true;//    // ...//}//public static bool operator true(object item)//{//    return true;//    // ...//}
}
  • 重载true和false 的操作符类型可以在 if、do、while 和for 语句的控制表达 式中使用

8、引用程序集

        开发者可以将程序的不同部分转移到单独的编译单元中,这些单元称为类库,或者简称库。 然后程序可以引用和依赖类库来提供自己的一部分功能。

更改程序集目标:

        编译器允许通过/target 选项创建下面4种不同的程序集类型  

  1. 控制台程序: 省略target 或者指定 /target:exe  
  2. 类库:/target: library
  3. Window 可执行程序:/target: winexe
  4. 模块:/target : module

引用程序集:    

        C# 允许开发者在命令行上引用程序集。方法是使用 /reference (/r)。

                例如:csc.exe /R:Coordinates.dll Program.cs

9、类型封装

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/84535.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

前后端分离毕设项目之产业园区智慧公寓管理系统设计与实现(内含源码+文档+教程)

博主介绍&#xff1a;✌全网粉丝10W,前互联网大厂软件研发、集结硕博英豪成立工作室。专注于计算机相关专业毕业设计项目实战6年之久&#xff0c;选择我们就是选择放心、选择安心毕业✌ &#x1f345;由于篇幅限制&#xff0c;想要获取完整文章或者源码&#xff0c;或者代做&am…

MySQL——函数和流程控制

2023.9.21 函数 含义&#xff1a;一组预先编译好的SQL语句的集合&#xff0c;理解成批处理语句。 提高代码的重用性简化操作减少了编译次数并且减少了和数据库服务器的连接次数&#xff0c;提高了效率 与存储过程的区别&#xff1a; 存储过程&#xff1a;可以有0个返回&am…

短视频抖音账号矩阵系统源码开发者自研(四)

抖音是一款备受欢迎的短视频APP&#xff0c;拥有数亿的用户&#xff0c;其中包括了大量的粉丝。为了让更多的人能够发现和观看到你的视频&#xff0c;抖音SEO是必不可少的一环&#xff0c;特别是对于拥有企业或个人品牌的用户来说。在这个过程中&#xff0c;抖音SEO源码的开源部…

SQL注入脚本编写

文章目录 布尔盲注脚本延时注入脚本 安装xampp&#xff0c;在conf目录下修改它的http配置文件&#xff0c;如下&#xff0c;找到配置文件&#xff1a; 修改配置文件中的默认主页&#xff0c;让xampp能访问phpstudy的www目录&#xff0c;因为xampp的响应速度比phpstudy快得多&am…

Linux C 网络基础

为什么需要网络通信&#xff1f; 进程间通信解决的是本机内通信 网络通信解决的是任意不同机器的通信 实现网络通信需要哪些支持 1.通信设备&#xff1a;网卡&#xff08;PC机自带&#xff09;&#xff1b; 路由器和交换机&#xff1b; 光纤…

在Scrapy框架中使用隧道代理

今天我要和大家分享一些实战经验&#xff0c;教你如何在Scrapy框架中使用隧道代理。如果你是一个热爱网络爬虫的开发者&#xff0c;或者对数据抓取和处理感兴趣&#xff0c;那么这篇文章将帮助你走上更高级的爬虫之路。 首先&#xff0c;让我们简单介绍一下Scrapy框架。Scrapy…

OpenCV自学笔记八:几何变换

1. 缩放&#xff08;Scale&#xff09;&#xff1a; 缩放是指改变图像的尺寸大小。在OpenCV中&#xff0c;可以使用cv2.resize()函数来实现图像的缩放操作。该函数接受源图像、目标图像大小以及插值方法作为参数。 示例代码&#xff1a;i mport cv2# 读取图像image cv2.imr…

【计算机网络】——应用层

// 图片取自王道 仅做交流学习 一、基本概念 应用层概述 协议是 网络层次模型 中多台主机之间 同层之间进行通信的规则。是一个水平概念 垂直空间上&#xff0c;向下屏蔽下层细节&#xff0c;向上提供服务接入&#xff0c;多台主机之间同层之间形成一条逻辑信道。 应用层的…

编译ctk源码

目录 前景介绍 下载The Common Toolkit (CTK) cmake-gui编译 vs2019生成 debug版本 release版本 前景介绍 CTK&#xff08;Common Toolkit&#xff09;是一个用于医学图像处理和可视化应用程序开发的工具集&#xff0c;具有以下特点&#xff1a; 基于开源和跨平台的Qt框…

Spring 6.0 新特性

文章目录 Spring的发展历史AOTGraalVMSpringBoot实战AOTRuntimeHints案例分析RuntimeHintsRegistrar SpringBoot中AOT核心代码 Spring的发展历史 AOT Spring 6.0的新特性Ahead of Time&#xff08;AOT&#xff09;编译是一种技术&#xff0c;可以提前将Spring应用程序编译成原…

【SpringCloud】微服务技术栈入门1 - 远程服务调用、Eureka以及Ribbon

目录 远程服务调用RestTemplate Eureka简要概念配置 Eureka 环境设置 Eureka ClientEureka 服务发现 Ribbon工作流程配置与使用 Ribbon饥饿加载 远程服务调用 RestTemplate RestTemplate 可以模拟客户端来向另外一个后端执行请求 黑马给出的微服务项目中&#xff0c;有两个 …

yolov5使用最新MPDIOU损失函数,有效和准确的边界盒回归的损失,优于GIoU/EIoU/CIoU/EIoU(附代码可用)

文章目录 1. 论文1.1. 主要目的1.2. 设计思路2 代码3.总结1. 论文 MPDIoU: A Loss for Efficient and Accurate Bounding Box Regression (一个有效和准确的边界框损失回归函数) 论文地址 1.1. 主要目的 当预测框与边界框具有相同的纵横比,但宽度和高度值完全不同时,大多数…

20230918使用ffmpeg将mka的音频转为AAC编码以便PR2023来识别

20230918使用ffmpeg将mka的音频转为AAC编码以便PR2023来识别 2023/9/18 20:58 ffmpeg -i 1.mka -acodec aac 1.mp4 ffmpeg -i 1.mka -vn -c:a aac 2.aac ffmpeg -i 1.mka -vn -c:a aac 2.MP4 ffmpeg mka 转 aacmp4 https://avmedia.0voice.com/?id42526 用ffmpeg将mka格式转化…

云端IDE的技术选型1

背景 考虑到以下几点&#xff0c;准备给低代码平台开发一套云端的IDE&#xff1a; 桌面端IDE&#xff1a;vs code 或 idea&#xff0c;都有需要开发人员安装ide&#xff0c;以及配置环境很多时候&#xff0c;配置开发环境是个非常曲折过程&#xff0c;经常出现版本不匹配&…

【分布式计算】副本数据Replicated Data

作用&#xff1a;可靠性、高性能、容错性 问题&#xff1a;如何保持一致、如何更新 问题&#xff1a;存在读写/写写冲突 一个简单的方法就是每个操作都保持顺序&#xff0c;但是因为网络延迟会导致问题 Data-centric models: consistency model?? ??? 读取时&#xff0c…

深入理解WPF中MVVM的设计思想

近些年来&#xff0c;随着WPF在生产&#xff0c;制造&#xff0c;工业控制等领域应用越来越广发&#xff0c;很多企业对WPF开发的需求也逐渐增多&#xff0c;使得很多人看到潜在机会&#xff0c;不断从Web&#xff0c;WinForm开发转向了WPF开发&#xff0c;但是WPF开发也有很多…

图像处理软件Photoshop 2024 mac新增功能

Photoshop 2024 mac是一款图像处理软件的最新版本。ps2024提供了丰富的功能和工具&#xff0c;使用户能够对照片、插图、图形等进行精确的编辑和设计。 Photoshop 2024 mac软件特点 快速性能&#xff1a;Photoshop 2024 提供了更快的渲染速度和更高效的处理能力&#xff0c;让用…

MyBatis 缓存模块

文章目录 前言缓存的实现Cache接口PerpetualCache 缓存的应用缓存对应的初始化一级缓存二级缓存第三方缓存 前言 MyBatis作为一个强大的持久层框架&#xff0c;缓存是其必不可少的功能之一&#xff0c;Mybatis中的缓存分为一级缓存和二级缓存。但本质上是一样的&#xff0c;都…

【异常错误】detected dubious ownership in repository ****** is owned by: ‘

今天在github git的时候&#xff0c;突然出现了这种问题&#xff0c;下面的框出的部分一直显示&#xff1a; detected dubious ownership in repository at D:/Pycharm_workspace/SBDD/1/FLAG D:/Pycharm_workspace/SBDD/1/FLAG is owned by: S-1-5-32-544 but the current use…

多线程的学习第二篇

多线程 线程是为了解决并发编程引入的机制. 线程相比于进程来说,更轻量 ~~ 更轻量的体现: 创建线程比创建进程,开销更小销毁线程比销毁进程,开销更小调度线程比调度进程,开销更小 进程是包含线程的. 同一个进程里的若干线程之间,共享着内存资源和文件描述符表 每个线程被独…