48 热度

What is NullReferenceException in C#?

In C#, a NullReferenceException occurs when we try to access a variable whose value has not been set or has been set to null. It can be easy to trigger this exception accidentally, so it’s important to be aware of how to avoid it in the first place. In this article, we’ll take a look at some common causes of NullReferenceException errors and how to fix them. We’ll also discuss ways to prevent NullReferenceException errors from happening in the first place.

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

FileSystemWatcher in C#

.NET provides a handy way to deal with monitoring different file system changes. In this article, we will discuss what FileSystemWatcher is, how to set it up, and how to configure it to observe various file system changes. In addition, we will take a look at the caveats of FileSystemWatcher.

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

Indexers in C#

In this article, we are going to learn about Indexers in C#, how to declare them in a class, struct, or interface, and overload them. We’re also going to learn what the differences between indexers and properties are.

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

Type Checking and Type Casting in C#

In this article, we are going to learn various ways of converting a value from one type to another (type casting) and how to check the type of a value at run time (type checking).

收录时间: 2022-08-08
分类: C#
贡献者: Rector
238 热度

C# 11新特性之原始字符串

朋友们大家好,我是Rector,码友网的创建者和维护者,专注C#&.NET技术开发。本文为大家分享的主题是《C# 11新特性之原始字符串》,本文相应的视频: C# 11新特性-原始字符串美国时间2022年4月18日,微软发布了Visual Studio 17.2 预览版 3和.NET 7预览版 3,其中包含了一些C# 11的新特性,本视频就为大家演示一下C# 11中的原始字符串这个新特性。微软官方的表述是:” Raw string literals”,这里翻译成”原始字符串”。从字面不难看出,它是适用于字符串的新特性,解决字符串中特殊字符的新语法。原始字符串字面量可以包含任意文本,包括空格、新...

收录时间: 2022-08-02
分类: C#
贡献者: Rector
192 热度

System.Text.Json - Polymorphic Serialization and Deserialization

In this article, we are going to deal with a special case of JSON processing, polymorphic serialization, and deserialization with System.Text.Json. The introduction of the System.Text.Json package has given .NET developers another powerful option for JSON format handling. You can get a full description of the package here.

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

C# 给Word每一页设置不同文字水印

Word中设置水印时,可预设的文字或自定义文字设置为水印效果,但通常添加水印效果时,会对所有页面都设置成统一效果,如果需要对每一页或者某个页面设置不同的水印效果,则可以参考本文中的方法。下面,将以C# 代码为例,对Word每一页设置不同的文字水印效果作详细介绍。

收录时间: 2022-07-27
分类: C#
贡献者: Rector
214 热度

Base64 Encode and Decode in C#

In this article, we will learn about how to Base64 encode and decode in C#.

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

How to Turn a C# Object Into a JSON String in .NET?

In this article, we’re going to learn how to serialize a C# object into a JSON string using the two main JSON libraries in the .NET ecosystem. Also, we’re going to learn how to control different aspects of the serialization process.

收录时间: 2022-07-14
分类: C#
贡献者: Rector
168 热度

Constructors in C#

In this article, we will discuss Constructors in C# and different types of constructors. More importantly, we will discuss these constructors’ differences and use cases.

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

Ranges and Indices in C#

In this article, we are going to learn more about ranges and indices in C#, and how to use them to access a single or a range of elements in a sequence. We’ll also see how ranges and indices help us write cleaner and more readable code.

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

Async Enumerable in C# (Part 3)

In this third part of my series on IAsyncEnumerable (part 1, part 2), let's discuss some of the differences between processing a sequence in parallel verses sequentially (sometimes referred to as "in series").

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

Using Refit to Consume APIs in C#

Consuming APIs over HTTP is a very common scenario when building applications. In this article, we are going to explore Refit to consume APIs in C#.

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

How to Use Span in C# to Improve Application Performance

Performance is always an important factor in software development. It is not something only the developers of a framework must consider. When the .NET team released the Span<> class they empowered developers to improve application performance, if used correctly. In this article, we will learn about Span in C#, how it is implemented, and how we can use it to increase performance.

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

C# Winform 相册功能,图片缩放,拖拽,预览图分页

在很多项目中也需要用到预览图片的功能,至于为什么加一个添加图片的功能,是因为有些项目,比如视觉相关的工作,会需要摄像机采集图片,然后显示在界面上,所以,图片也是一张一张的添加的,另外,就是分页功能,当预览图位置不够用时就会用到,所以我也加了进来。

收录时间: 2022-06-27
分类: C#
贡献者: Rector
AD 友情赞助
165 热度

C# Winform 自定义进度条ProgressBar

Winfrom各种老毛病真的不适合做大型项目,甚至中型项目都不适合,一些小功能都能把你折腾半死,比如,我想在界面上显示一个进度条,用来显示现在硬盘和内存已经使用了多少,使用了 ProgressBar 控件你看看效果:进度条中间一直有个白色光影在晃来晃去的,是不是想让别人感慨:“哇!好强的光芒,我的眼睛快睁不开了...”。而且背景颜色无法改变,这个动画也无法关掉,为了解决这两个问题,我找了很久,终于找到了下面的解决方法。二、自定义进度条于是我在网上找了一些资料,有到效果有,但不是特别漂亮,比如下面这个C# WinForm 自定义进度条控件_科技_品阅网另外,我参考了下面到帖子Win...

收录时间: 2022-06-27
分类: C#
贡献者: Rector
200 热度

Async Enumerable in C# (Part 2)

In this second part of my series on IAsyncEnumerable (part 1 is here), I want to consider what happens when we want to make asynchronous calls within a LINQ pipeline. This is actually something that's very difficult to achieve with an IEnumerable but much more straightforward with IAsyncEnumerable.

收录时间: 2022-06-27
分类: C#
贡献者: Rector
198 热度

Remove Duplicates From a List in C#

In this article, we will learn the different methods to remove duplicates from a list in C#. List is a collection having elements of the same type which can contain multiple occurrences of the same item. Sometimes, we want that every element is unique, and here we will check various ways to achieve this goal, comparing their performance.

收录时间: 2022-06-27
分类: C#
贡献者: Rector
167 热度

How to Call Generic Method Using Reflection in C#

In this article, we are going to learn how to call a generic method in C# using reflection. Generic methods are an all-time favorite of library developers for their inherent reusability and type inference benefits. But because of the need for explicit type arguments in most cases (except when type inference occurs implicitly), we can’t always make the best use of them in compile time. This is where reflection comes into play.

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

Runtime C# Code Compilation Revisited for Roslyn

In this post I'll talk about the process of using the Roslyn C# Code compilation APIS and the why's and how's of creating a WestWind.Scripting wrapper and more importantly how I actually use it in one of my popular applications.

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