26 热度

C#中普通缓存的使用

缓存的概念及优缺点在这里就不多做介绍,当然缓存包含多种有普通缓存、客户端缓存、DNS缓存、反向代理缓存以及分布式缓存等等。今天主要聊一聊C#通过编码来实现普通的缓存、话不多说直接上代码。

收录时间: 2021-05-06
分类: C#开发
贡献者: Rector
21 热度

C#: Make your delegates asynchronous from synchronous delegates

I wanted to write this post because I realized that a lot of developers have difficulty writing asynchronous delegates. I often see synchronous delegates in code review that could be transformed. So in this post I will show you how to proceede without however going over the usefulness of asynchronism, this is not the purpose of this post.

收录时间: 2021-05-06
分类: C#开发
贡献者: Rector
49 热度

浅谈在c#中使用Zlib压缩与解压的方法

近期用c#开发一个游戏的存档编辑工具需要用 Zlib 标准的 Deflate 算法对数据进行解压。 在 StackOverflow 上逛了一圈,发现 c# 比较常用到的方式是微软提供的 System.IO.Compression, zlib.net, 以及 ICSharpCode 的SharpZipLib。我简单的测试和包装了一下,便在这里分享一下成果以及我个人的看法。

收录时间: 2021-04-28
分类: C#开发
贡献者: Rector
51 热度

2021 C# Exception Handling Best Practices

C# Exception Handling Best Practices, Regarding the basic grammar and function of exceptions, I won’t repeat them here. Let me record some thoughts about Exceptions in the project.

收录时间: 2021-04-19
分类: C#开发
贡献者: Rector
84 热度

Announcing Open Source C# standardization

The C# compilers have been open source since 2014, now in the dotnet/roslyn repository. The dotnet/csharplang split off to provide a dedicate public space for the innovation and evolution of the C# language. Now, dotnet/csharpstandard completes the group, providing a public space for the ongoing work to document the standard for the latest C# language versions.

收录时间: 2021-04-06
分类: C#开发
贡献者: Rector
77 热度

C# 9 top-level programs and target-typed expressions

.NET 5 (released in November 2020) includes support for C# 9, a major new version of the C# programming language. This series of articles explores the new features in .NET’s main programming language. In this first article, we’ll look at top-level statements and target-typed new and conditional expressions. These features make C# less verbose and can be used in everyday programs.

收录时间: 2021-04-01
分类: C#开发
贡献者: Rector
AD 友情赞助
120 热度

Introduction to string interpolation

In this article, we continue to explore string manipulations by focusing on interpolation. Instead of concatenating many pieces together, interpolation allows us to insert special tokens inside a string. A value then replaces those tokens. Interpolation and concatenation play the same role, but often one ends up being more elegant than the other and makes the code easier to maintain.

收录时间: 2021-03-29
分类: C#开发
贡献者: Rector
145 热度

在C#中使用 CancellationToken 处理异步任务

在 .NET Core 中使用异步编程已经很普遍了, 你在项目中随处可见 async 和 await,它简化了异步操作,允许开发人员,使用同步的方式编写异步代码,你会发现在大部分的异步方法中,都提供了CancellationToken参数,本文主要介绍下 CancellationTokenSource 和 CancellationToken在异步任务中的使用。

收录时间: 2021-03-17
分类: C#开发
贡献者: Rector
120 热度

Unit Testing 101: Write your first unit test in C# with MSTest

Do you want to start writing unit tests and you don't know how to start? Were you asked to write some unit tests on a past interview? Let's see what is a unit test and how to write your first unit tests in C#.

收录时间: 2021-03-16
分类: C#开发
贡献者: Rector
88 热度

dotnet C# 序列化 XML 时进行自动格式化

默认的序列化对象为 XML 字符串时,是没有进行格式化的,也就是所有的内容都在相同的一行。本文告诉大家方法,在序列化对象时,转换的 XML 是格式化的。或者说拿到 XML 字符串,对这个 XML 字符串进行格式化...

收录时间: 2021-03-08
分类: C#开发
贡献者: Rector
142 热度

C# 9.0: Pattern Matching in Switch Expressions

In this blog post, let’s look at C# 9.0 pattern matching in switch expressions. In the previous blog post you learned about using patterns with the is pattern expression, and you learned about the new relational patterns in C# 9.0, and also about the new pattern combinators and and or. If you haven’t read the previous blog post, I recommend you to read it, as I don’t repeat the basics of relational patterns and pattern combinators in this blog post.

收录时间: 2021-02-26
分类: C#开发
贡献者: Rector
128 热度

C#/WinRT Authoring Preview and Updates

The C#/WinRT team is excited to announce our latest release, which includes a preview of C#/WinRT authoring with the latest C#/WinRT NuGet package, as well as updates to the .NET 5.0 SDK with the .NET February update. Since our last blog post on C#/WinRT v1.0, we have some new features to show off!

收录时间: 2021-02-10
分类: C#开发
贡献者: Rector
213 热度

如何在 C# 中使用 Thread

线程是进程中的最小执行单元,多线程是指在给定时间内拥有多个线程的能力,并且可以调度它们从而在某一时刻处理多个操作,微软的 .Net Framework 提供了 Thread 来帮助我们完成多线程开发。

收录时间: 2021-01-27
分类: C#开发
贡献者: Rector
147 热度

C# 合并和拆分PDF文件

PDF文件使用了工业标准的压缩算法,易于传输与储存。它还是页独立的,一个PDF文件包含一个或多个“页“,可以单独处理各页,特别适合多处理器系统的工作。PDF文件结构主要可以分为四个部分:首部、文件体、交叉引用表、尾部。PDF操作类库非常多,如下图所示,常用的类库有:Spire.Pdf、iTextSharp。

收录时间: 2021-01-23
分类: C#开发
贡献者: Rector
127 热度

如何在 C# 8 中使用 异步流

异步编程已经流行很多年了,.NET 引入的 async 和 await 关键词让异步编程更具有可读性,但有一个遗憾,在 C# 8 之前都不能使用异步的方式处理数据流,直到 C# 8 引入的 IAsyncEnumerable 才解决了这个问题。

收录时间: 2021-01-19
分类: C#开发
贡献者: Rector
AD 友情赞助
131 热度

使用 C# 9 的records作为强类型ID - 路由和查询参数

上一篇文章,我介绍了使用 C# 9 的record类型作为强类型id,非常简洁....但是在强类型id真正可用之前,还有一些问题需要解决,比如,ASP.NET Core并不知道如何在路由参数或查询字符串参数中正确的处理它们,在这篇文章中,我将展示如何解决这个问题。路由和查询字符串参数的模型绑定假设我们有一个这样的实体...

收录时间: 2021-01-18
分类: C#开发
贡献者: Rector
127 热度

Base64 Encoding With C#

I was working with the Spotify API and reading through the authorization documentation. Like most APIs, we need to securely access the service, authorized as the client application or on behalf of a user. We’ll need to deal with secret tokens and likely encode them into a Base64 string in that process. The client credentials flow requires we concatenate the service provided secrets of clientId and clientSecret, after which we Base64 encode the result.

收录时间: 2021-01-15
分类: C#开发
贡献者: Rector
115 热度

Generate TypeScript and C# clients with NSwag based on an API

Generating clients for APIs is a tremendous way to reduce the amount of work you have to do when you’re building a project. Why handwrite that code when it can be auto-generated for you quickly and accurately by a tool like NSwag? To quote the docs

收录时间: 2021-01-12
分类: C#开发
贡献者: Rector
202 热度

C# 9 新特性 —— 补充篇

前面我们分别介绍了一些 C# 9 中的新特性,还有一些我觉得需要了解一下的新特性,写一篇作为补充。在以往的代码里,一个应用程序必须要有 Main 方法才能运行,从 C# 9 开始,支持没有 Main 方法的程序,实际编译之后还是会有一个 Main 方法的,使用示例如下...

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

Creating a Business Rule Engine Using Dynamic Expression Predicates With C#

A developer gives a tutorial on how to create a dynamic business rule engine using the C# language, providing all the code you need to follow along.

收录时间: 2021-01-04
分类: C#开发
贡献者: Rector
AD 友情赞助