15 热度

Raw String Literals In C# 11 - .NET Core Tutorials

Recently I was trying to write a unit test that required me to paste in some known JSON to validate against. Sure, I could load the JSON from a file, but I really don’t like File IO in unit tests. What it ended up looking like was something similar to...

收录时间: 2022-05-16
分类: C#
贡献者: Rector
28 热度

How to Convert JSON to XML or XML to JSON in C#

In this article, we are going to learn how to convert JSON to XML and XML to JSON in C#.

收录时间: 2022-05-13
分类: C#
贡献者: Rector
33 热度

Using the when Keyword in C# While Handling Exceptions

In this article, we are going to learn why and how to use the when keyword within try-catch blocks while handling exceptions in C#. We cannot avoid the occurrence of exceptions in the life cycle of an application. An exception is a problem that appears unexpectedly from our codebase. Exception handling is the process of building a system that can detect and manage exceptions. Exceptions that are not handled properly can completely disrupt the flow of our application.

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

C# 编写一个简单易用的 Windows 截屏增强工具

半年前我开源了 DreamScene2一个小而快并且功能强大的 Windows 动态桌面软件。有很多的人喜欢,这使我有了继续做开源的信心。这是我的第二个开源作品 ScreenshotEx一个简单易用的 Windows 截屏增强工具。欢迎 Star 和 Fork https://github.com/he55/ScreenshotEx前言在使用 Windows 系统的截屏快捷键 PrintScreen 截屏时,如果需要把截屏保存到文件,需要先粘贴到画图工具然后另存为文件。以前我还没有觉得很麻烦,后来使用了 macOS 系统的截屏工具,我才知道原来一个小小的截屏工具也可以这么简单易用。于是参考...

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

How to Read Data From a CSV File in C#

Reading from a CSV file in C# is a common operation. In this article, we are going to show how to easily read data from a CSV file in C# using the CSVHelper NuGet package.

收录时间: 2022-05-11
分类: C#
贡献者: Rector
40 热度

站在前人的肩膀上重新透视C# Span数据结构

Span和Memory都是包装了可以在pipeline上使用的结构化数据的内存缓冲器,他们被设计用于在pipeline中高效传递数据。

收录时间: 2022-05-10
分类: C#
贡献者: Rector
AD 友情赞助
74 热度

Priority Queue in C#

Priority Queue in C# is a very useful data structure that has so many real-world applications. In this article, we are going to cover the main concepts of Priority Queue in C#. We have covered the basic Queue in C#, it is recommended to check it out before continuing with this article.

收录时间: 2022-04-29
分类: C#
贡献者: Rector
54 热度

How to generate Fake data in C#?

The reason for generating fake data can be anything. But, the most common use case I think for generating fake data is when someone is dependent on the result from your API.As a backend developer, you’ve to just create a model and return a few fake objects that represent data.We could however create...

收录时间: 2022-04-26
分类: C#
贡献者: Rector
54 热度

Annotating your C# code - Migrating to nullable reference types - Part 3

In the previous post, we looked at some internals of C# nullable reference types, and the nullable annotation context. Today, let’s look at the many options for annotating your code and various ways to help the flow analysis understand your code. As a result, you (and anyone consuming your libraries) will get better and more reliable hints from the IDE and the C# compiler.

收录时间: 2022-04-26
分类: C#
贡献者: Rector
59 热度

JSON Deserialization to a POCO Class in C#

Deserialization is the process of taking a string representation of an object and creating that object in memory. JSON is an ever-increasingly popular format to serialize objects into. It has become nearly ubiquitous in API communication. In this article, we will take a look at two ways to execute the JSON deserialization to a POCO class in C# using System.Text.Json and Newtonsoft.Json libraries.

收录时间: 2022-04-21
分类: C#
贡献者: Rector
56 热度

Using dotnet format Command to Format the C#/.NET Code

In this article, we are going to look into a global .NET tool called dotnet format, that helps with code styling in our .NET applications. We’ll explore the basic usage, how the role of .editorconfig is important, and how to make the best use of the dotnet format in our development process.

收录时间: 2022-04-20
分类: C#
贡献者: Rector
51 热度

C# 11 Preview Updates - Raw string literals, UTF-8 and more!

Features for C# 11 are coming along nicely! You can check these features out by downloading Visual Studio 17.2 Preview 3 or .NET 7 Preview 3 for other editors. You can find more about C# 11 features that appeared earlier in What’s new in C# 11 and Early peek at C# 11 features and you can follow the progress of C# 11 on the Feature Status page. You can find out about other .NET 7 Preview 3 features in this .NET Blog post and more about Visual Studio 17.2 in the release notes.

收录时间: 2022-04-19
分类: C#
贡献者: Rector
62 热度

C#面向抽象编程第二讲

抽象编程怎么说呢,以观察者模式为例:观察者模式有两个对象,一个是观察者,一个是可观察者(字面翻译很别扭observable),消息发布者(提供者)。第一层如下,三个对象A、B、C分别有一个接收消息的方法,还有一个存储数据的字段,X就是发布消息的对象,它通过setdata方法设置自己的字段data,然后通知abc,abc如愿以偿地拿到了通知,完美!

收录时间: 2022-04-15
分类: C#
贡献者: Rector
63 热度

c#中判断类是否继承于泛型基类

在c#中,有时候我们会编写类似这样的代码:public class a{ //具体类的实现}public class b : a{}如果b继承a的类型不确定,这个时候我们是无法通过baseType来直接判断b是否继承于a的。如果我们写如下代码:typeof(b).baseType == typeof(a)返回值是false。因为typeof(b).baseType返回的类型是a`1[System.String],而typeof(a)返回的是a`1[T]。很明显这两个类型是不相等的。所以上面返回flase也就是正常现象了。那么如何解决这个问题呢?最简单的办法肯定是typeof(b).base...

收录时间: 2022-04-15
分类: C#
贡献者: Rector
60 热度

Try-Catch Block in C#

Sometimes our application crashes due to unexpected errors and exceptions that occur during the program execution. So, in this article, we are going to discuss the try-catch block in C# and learn how to handle those exceptions.

收录时间: 2022-04-14
分类: C#
贡献者: Rector
AD 友情赞助
69 热度

Different Ways to Print The Elements of an Array in C#

In this article, we are going to explore how to print the elements of an array in C#. Also, we are going to compare these approaches to check which are the fastest and the slowest ones.

收录时间: 2022-04-13
分类: C#
贡献者: Rector
79 热度

Random Class in C#

You might be wondering why would we need the Random Class in C#? One obvious example that comes to mind would be computer games. Whether attempting to simulate the rolling of dice or mimicking a random event, getting the same result every time would clearly not be fun. Perhaps a more serious example would be in the world of cryptography, which requires random number generation for encryption algorithms. Even simple applications, such as randomly selecting a person from a database to be a juror, require the use of generating a random result. As such, we are going to explore throughout this article how to use the Random Class in C# to generate these random results.

收录时间: 2022-04-12
分类: C#
贡献者: Rector
75 热度

Nullable reference types in C# - Migrating to nullable reference types - Part 1

Throughout a series of blog posts, we’ll learn more about C# nullability, and cover some techniques and approaches that worked for me when migrating an existing codebase to using nullable reference types.

收录时间: 2022-04-12
分类: C#
贡献者: Rector
75 热度

LINQ to XML

LINQ to XML is an in-memory XML programming interface that provides LINQ functionality to programmers. Like the Document Object Model (DOM), we can use LINQ to XML to load XML documents into memory. However, this way we can process them more efficiently, using the advanced features of LINQ.

收录时间: 2022-04-12
分类: C#
贡献者: Rector
78 热度

How to Deserialize JSON Into Dynamic Object in C#

In this article, we are going to learn how to deserialize JSON into a dynamic object in C#. To download the source code for this article, you can visit our GitHub repository.JSON deserialization in C# refers to the process of forming up .NET objects from a JSON string. Most of the time, this means...

收录时间: 2022-04-07
分类: C#
贡献者: Rector
AD 友情赞助