ReSharper warns: “Static field in generic type”
2024-08-22 23:39:00
http://stackoverflow.com/questions/9647641/resharper-warns-static-field-in-generic-type
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<T>
{
// Of course we wouldn't normally have public fields, but...
public static int Foo;
} public class Test
{
public static void Main()
{
Generic<string>.Foo = ;
Generic<object>.Foo = ;
Console.WriteLine(Generic<string>.Foo); //
}
}
As you can see, Generic<string>.Foo
is a different field from Generic<object>.Foo
- they hold separate values.
最新文章
- ImportError: cannot import name &#39;check_arrays&#39;
- 所有HTTP请求参数及报文查看SERVLET
- 进阶——scrapy登录豆瓣解决cookie传递问题并爬取用户参加过的同城活动&#169;seven_clear
- Java ClassLoader基础及加载不同依赖 Jar 中的公共类
- 实例化Model的三种方式
- android style 中一些颜色的定义
- 定义member【C++】cstddef中4个定义
- ethtool 在 Linux 中的实现框架和应用
- Linux中 pid_t 类型的定义.
- js格式转换
- python 九九乘法表!小练习
- ajax 动态添加商品列表
- ReactNative 基础学习
- 防盗链与token运用
- Git 密钥对处理
- Office 365平台及其价值主张
- CSS层叠样式表(Cascading Style sheets)
- (后端)Mybatis实现批量删除操作(转)
- bzoj4773: 负环
- 关于 HTTP