48 热度

C# File.Exists 判断系统文件,警惕32位和64位的差异

今天在调试一个Winform程序,使用File.Exists 判断一个已经存在的驱动文件,程序一直返回false。因为驱动文件属于系统目录,心想难道是权限不够导致的?然后用管理员身份运行软件,依然返回false。吓的我赶紧去系统目录C:\Windows\system32\drives 搜索该文件,一看在这里啊,怎么还是返回false。开始还以为VS出问题了,然后尝试判断一个D盘下的文件,发现可以判断成功。

收录时间: 2020-07-27
分类: C#开发
贡献者: Rector
49 热度

C# 9: Putting it all together with a scavenger hunt

Here we are, friends: our last post in our C# 9 deep dive series. We’ve discussed a lot of topics, so I thought it’d be fun to bundle all we’ve learned into a single post. (You can think of this as a CliffsNotes of the 10,000 or so words I’ve written about C# 9 so far.)

收录时间: 2020-07-23
分类: C#开发
贡献者: Rector
43 热度

C# 9: Minor Improvements for Lambdas

Lambdas will be getting a small upgrade in C# 9 with two new features. Neither will change the way code is written, but they do clarify the developer’s intent.

收录时间: 2020-07-23
分类: C#开发
贡献者: Rector
47 热度

C# 9: Range Operators in Switch Constructs and Pattern

Since C# was first introduced, developers have complained about the lack of a range operator in switch constructs. This made switches far less useful in C# than they were in VB. As part of the pattern-matching enhancements for C# 9, this limitation has been addressed.

收录时间: 2020-07-18
分类: C#开发
贡献者: Rector
58 热度

C# 9 Deep Dive: Target Typing and Covariant Returns

We’ve been quite busy, my friends. In this C# 9 deep dive series, we’ve looked at init-only features, records, pattern matching, and then top-level programs. To complete this series (before showing off everything in a single app), we’ll discuss the last two items featured in the Build 2020 announcement: target typing and covariant returns. These are not related, but I’ve decided to bundle these in a single blog post. This is the fifth post in a six-post series on C# 9 features in-depth...

收录时间: 2020-07-16
分类: C#开发
贡献者: Rector
28 热度

C# 8.0 nullable references: more type system transcendence with DisallowNull

In my last blog in this series, I talked about the AllowNull attribute. This post shows its converse, DisallowNull. As with all the attributes relating to nullable references, the goal is to improve expressiveness, enabling the compiler to report more nullable-related problems without producing spurious warnings.

收录时间: 2020-07-15
分类: C#开发
贡献者: Rector
AD 友情赞助
48 热度

Implementation of the C# IO container

This article is part of an article series about the IO container in C#. In the previous articles, you've seen how a type like IO can be used to distinguish between pure functions and impure actions. The point of the article series is to illustrate the concept that Haskell uses to impose the functional interaction law at compile time. The implementation details really aren't important. Still, I believe that I know my readership well enough that a substantial fraction would be left unsatisfied if I didn't share the implementation details.

收录时间: 2020-07-14
分类: C#开发
贡献者: Rector
52 热度

C#各类集合介绍

集合(Collection)类是专门用于数据存储和检索的类。这些类提供了对栈(stack)、队列(queue)、列表(list)和哈希表(hash table)的支持。大多数集合类实现了相同的接口。平常在工作中List集合是用的最多的,其次是Array(数组).今天整理一下各类形式的集合,不用就容易忘,必须要记录一下...

收录时间: 2020-07-13
分类: C#开发
贡献者: Rector
65 热度

Regex Named Groups and Using Them in C#

While working on an issue in Codespaces, I figured this would be a good case to implement some regex. Each time I work with regex I need to figure out how it works again, but also each time I am impressed with how powerful it is. And actually, this time I learned something new: regex named groups. Regex has the ability to name each matched group which is very easy to subsequently use in C# code. In this post, I will tell you how to do exactly that.

收录时间: 2020-07-10
分类: C#开发
贡献者: Rector
54 热度

C# dotnet 使用 FileStream 随机文件读写

本文说的随机文件读写的随机的反义词是顺序,这里的随机文件读写对应顺序文件读写。表示文件可以不按照顺序进行读写。进行文件读写的时候,基本上读是几乎不存在问题的,而写的话就稍微坑了一点,在 dotnet 里面默认没有提供 RandomAccessStream 类,这个 RandomAccessStream 类仅在 UWP 中可以使用。如果在不引用 UWP 的 WPF 里面,或者在 ASP.NET Core 以及 Xamarin 里面,也可以通过 FileStream 的 Seek 方法做到进行随机的读写...

收录时间: 2020-07-07
分类: C#开发
贡献者: Rector
69 热度

C# Futures: Null Check Operator

In the June 24th C# Language Design Meeting, Microsoft made a subtle change to the parameter null checking syntax. By changing it from Type parameterName! to Type parameterName!! they effectively introduced a new ‘null check operator’.

收录时间: 2020-07-03
分类: C#开发
贡献者: Rector
79 热度

C# 从1到Core--委托与事件

委托与事件在C#1.0的时候就有了,随着C#版本的不断更新,有些写法和功能也在不断改变。本文温故一下这些改变,以及在NET Core中关于事件的一点改变。一、C#1.0 从委托开始1. 基本方式什么是委托,就不说概念了,用例子说话。某HR说他需要招聘一个6年 .NET5 研发经验的“高级”工程师,他想找人(委托)别人把这条招聘消息发出去。这样的HR很多,所以大家定义了一个通用的发消息规则:public delegate string SendDelegate(string message);这就像一个接口的方法,没有实际的实现代码,只是定义了这个方法有一个string的参数和返回值。所有想发招...

收录时间: 2020-07-01
分类: C#开发
贡献者: Rector
59 热度

C# 9 Deep Dive: Init-only features

A few weeks ago, we took a quick tour of some upcoming C# 9 features that will make your development life easier. We dipped our toes in the water. But now it’s time to dig a little deeper.I’m starting a new series over the next several weeks, that will showcase all of the announced featuresincrement...

收录时间: 2020-07-01
分类: C#开发
贡献者: Rector
69 热度

Misusing C#: Multiple Main() Methods

Sometimes you run across things you should probably never do in real life but are possible in your development environment. Having more than one "Main()" method in an application is one of those things in the .NET world.

收录时间: 2020-07-01
分类: C#开发
贡献者: Rector
69 热度

C# 9.0 新特性之 Lambda 弃元参数

大家好,这是 C# 9.0 新特性短系列的第 5 篇文章。弃元(Discards) 是在 C# 7.0 的时候开始支持的,它是一种人为丢弃不使用的临时虚拟变量。语法上它是用来赋值的,但它却不被分配存储空间,即没有值,所以不能从中读取值。弃元用 _(下划线) 表示,下划线是一个关键字,只能赋值,不能读取,例如...

收录时间: 2020-06-30
分类: C#开发
贡献者: Rector
AD 友情赞助
50 热度

C# 8.0 nullable references: NotNull

So far in this sub-series on attributes for getting better results from C# 8's nullable references feature I've described the AllowNull and DisallowNull attributes. Now it's NotNull's turn. As with all of these attributes, this enables us to describe our intent in more detail so that the compiler can find more null-related programming errors without producing spurious warnings. This particular post is concerned with a scenario where the successful execution of a method implies that we can now be certain that something isn't null, and we'd like the compiler to know that.

收录时间: 2020-06-30
分类: C#开发
贡献者: Rector
73 热度

Differences between String and string in C#

In this article, we’re going to tackle the popular question among many developers, and that’s “What’s the difference between string and String” and “When should I use string, and when should I use String” in my applications. Both of these versions exist for a reason, so let’s see what they are and if they’re indeed that important.

收录时间: 2020-06-24
分类: C#开发
贡献者: Rector
74 热度

Introducing C# 9: Improved pattern matching

Pattern matching has been introduced in C# 6 and has well evolved since. The latest improvement was pretty interesting on C# 8 which has been released last year. If you missed pattern matching improvements on C# 8 , here is a nice article from Miguel Bernard (@MiguelBernard88): https://blog.miguelbernard.com/pattern-matching-in-csharp/. If you have missed all new features in C# 8, you can read also his great serie here: https://blog.miguelbernard.com/csharp-8-0-new-features/. In this article I will show you all the great new features of pattern matching.

收录时间: 2020-06-24
分类: C#开发
贡献者: Rector
66 热度

分享一套全网最佳 C# 与 .NET 设计模式视频教程(共124讲)

大家好,今天给大家分享一套 C# 与 .NET 设计模式视频教程,目前是我发现的基于 .NET 来讲设计模式的教程中最好也是最全的一套(含配套源代码)。我每天上下班中上都看两集,今天终于看完了(中间对于非常简单的知识点使用了 1.25 倍加速)。尽管我是个 .NET 老司机,但看完后依然收获不少。至少你能有如下收获...

收录时间: 2020-06-23
分类: C#开发
贡献者: Rector
71 热度

在运行时生成C# .NET类

在我的C#职业生涯中,有几次我不得不在运行时生成新的类型。希望把它写下来能帮助有相同应用需求的人。这也意味着我以后不必在查找相同问题的StackOverflow文章了。我最初是在.NET 4.6.2中这样做的,但我已经更新到为.NET Core 3.0提供了示例。所有代码都可以在我的GitHub上面找到。

收录时间: 2020-06-23
分类: C#开发
贡献者: Rector
AD 友情赞助