博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ReSharper warns: “Static field in generic type”
阅读量:6875 次
发布时间:2019-06-26

本文共 702 字,大约阅读时间需要 2 分钟。

It's fine to have a static field in a generic type, so long as you know that you'll really get one field per combination of type arguments. My guess is that R# is just warning you in case you weren't aware of that.

Here's an example of that:

using System;public class Generic
{ // Of course we wouldn't normally have public fields, but... public static int Foo;}public class Test{ public static void Main() { Generic
.Foo = 20; Generic
.Foo = 10; Console.WriteLine(Generic
.Foo); // 20 }}

 

As you can see, Generic<string>.Foo is a different field from Generic<object>.Foo - they hold separate values.

 

转载地址:http://naofl.baihongyu.com/

你可能感兴趣的文章
Swoole 源码分析——内存模块之swBuffer
查看>>
CORS跨域
查看>>
进行版本迭代过程中,使用spring jpa来完美解决数据表更新的问题
查看>>
分享一个用react-native写的app,适合新手学习react-native
查看>>
React之PureComponent
查看>>
node网络爬虫实例了解下?
查看>>
js对象(一)——创建对象
查看>>
用JavaScript访问SAP云平台上的服务遇到跨域问题该怎么办
查看>>
仅使用NumPy完成卷积神经网络CNN的搭建(附Python代码)
查看>>
position fixed的相对容器是什么
查看>>
MySQL 5.7 Windows安装与配置
查看>>
Swoft 源码剖析 - Swoft 中 AOP 的实现原理
查看>>
在vue2.x项目使用flexible.js和sass
查看>>
node.js学习之npm 入门 ——1.《npm是什么》
查看>>
数据结构JavaScript描述(三)
查看>>
在vue项目中引用element-ui时 让el-input 获取焦点的方法
查看>>
理解React组件生命周期
查看>>
交易是所有权的转移
查看>>
在windows上安装最新版powershell并代替原版在文件中shift右键启动,并修改样式。...
查看>>
Spring Cloud构建微服务架构:分布式服务跟踪(收集原理)【Dalston版】
查看>>