43 热度

CRUD Operations with C# WinForms(.Net Framework)

This is a complete 101 discussion specifically written for my students, but this would be helpful for anyone to get a headstart with the C# WinForms application.

收录时间: 2021-06-07
分类: C#
贡献者: Rector
89 热度

[翻译] 预览 C# 10 的新东西

本周早些时候(译注:原文发表于5月1日),我关注了 Mads Torgersen 在 DotNet SouthWest 大会上的演讲,他是微软的 C# 语言的首席设计师。他概述了 C# 10 即将包含的很酷的一些新东西。让我们来快速浏览一下。

收录时间: 2021-06-02
分类: C#
贡献者: Rector
60 热度

C# Windows Form - Creating PDF documents using iText7 library

In this post we will see how we can create PDF documents in C# Windows forms using iText7 library. The final PDF file contains Product details in a table format, seller information and customer information. It is a sample PDF invoice document. You are required to install iText7 library nuget package in your Windows forms application project using the Nuget Package manager option.

收录时间: 2021-06-02
分类: C#
贡献者: Rector
37 热度

编写你的专属 MSBuild C# 代码生成器:在保存文件时自动实时生成你的代码

我之前的博客中有介绍如何在项目中生成额外的代码,也有介绍制作一个生成代码的 NuGet 包。而本文是在此基础上更进一步,可以让生成代码变成实时的;更准确的说,是在保存文件时即生成代码,而无需完整编译一次项目。一天,头像全白昵称空格的“wuweilai”童鞋问我为什么 GRPC 的 NuGet 包能自动在 .proto 文件保存时更新生成的代码,怎么才能做到像它那样。然后,我研究了下 Grpc.Tools 包里的代码,外加跟他反复讨论,摸清了自动生成代码的方法。

收录时间: 2021-06-02
分类: C#
贡献者: Rector
73 热度

C#异常处理18条最佳实践

首先,异常处理应该是系统设计规约的一部分出现在系统设计文档中,而不仅仅是一种技术实现。作为设计文档的一部分,异常处理应该着眼于系统容错性和稳定性(正如楼主提到的那样)。然后在根据这个规约,再来具体讨论和选择异常处理中使用的各种技术细则。 比如,在设计服务时,必须在服务的调用接口处有异常处理,否则客户端传过来的任何有害数据都可能让服务器挂掉。

收录时间: 2021-06-02
分类: C#
贡献者: Rector
89 热度

C#基础之GetType 与 typeof的区别

在实际开发中经常需要了解具体对象的类型,所以经常会使用GetType()和typeof()、尽管可以得到相应的类型、但两者之间也存在一些差别,接下来我们一起来了解一下吧。

收录时间: 2021-06-02
分类: C#
贡献者: Rector
AD 友情赞助
79 热度

dotnet C# 实现 GetHashCode 的方法

本文来聊聊在重写某个类的 GetHashCode 方法时,可以如何实现 GetHashCode 的返回值。按照 GetHashCode 方法的原则,要求两个对象如果 Equals 返回 true 那么一定要求 GetHashCode 也返回相同的值。当然,反过来不成立,也就是两个对象返回的 GetHashCode 的值相同,对象可以是不相等的。实现 GetHashCode 方法的方式有很多,最简单的就是通过调用基类的 GetHashCode 方法,代码如下...

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

Custom User Message Extension Methods in C# and MVC

Since I primarily work on internal business applications, I often find myself writing the same kinds of code multiple times. One of the most common situations is a "status message" or some kind of display to the user that lets them know that something successfully happened, or there's some kind of error, or warning, or just a friendly reminder...

收录时间: 2021-05-19
分类: C#
贡献者: Rector
61 热度

Using C# Named Arguments to Declutter Complex Tests

I've got a quick tip this week, about tests and a cool feature of C#. For better or for worse, my team and I often build projects that are large, complex beasts. In all of them, we prefer to use Dependency Injection as a way to construct complex objects.

收录时间: 2021-05-12
分类: C#
贡献者: Rector
133 热度

C#中普通缓存的使用

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

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

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
116 热度

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

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

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

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
150 热度

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
135 热度

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 友情赞助
174 热度

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
215 热度

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

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

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

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
123 热度

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

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

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

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
AD 友情赞助