小编Kee*_*Wit的帖子

async/await和IDisposable接口

我有一个实现IDisposable接口的类来处理私有变量_MailMessage同一个类有一个使用私有IDisposable变量的异步方法,即async public Task<bool> Send我的问题是:在异步方法完成后,普通的IDisposable实现是否会处理私有变量?这是我正在谈论的课程的一个例子:

public class Email : IEmail
{
    private readonly IEmailData _EmailData;
    private MailMessage _MailMessage = new MailMessage();

    public Email(IEmailData emailData)
    {
        if (emailData == null)
        {
            throw new ArgumentNullException("emailData");
        }
        if (String.IsNullOrEmpty(emailData.To))
        {
            throw new ArgumentNullException("emailData.To");
        }
        if (String.IsNullOrEmpty(emailData.From))
        {
            throw new ArgumentNullException("emailData.From");
        }
        if (String.IsNullOrEmpty(emailData.FromName))
        {
            throw new ArgumentNullException("emailData.FromName");
        }
        if (String.IsNullOrEmpty(emailData.Subject))
        {
            throw new ArgumentNullException("emailData.Subject");
        }
        if (String.IsNullOrEmpty(emailData.Body))
        {
            throw new ArgumentNullException("emailData.Body");
        }

        _EmailData = emailData;
    }


    async public Task<bool> Send() …
Run Code Online (Sandbox Code Playgroud)

c# idisposable async-await

8
推荐指数
2
解决办法
7983
查看次数

如何判断字节数组是否被gzip压缩

如何查看字节数组是否包含gzip流?我的应用程序通过带有Base64编码的http post从其他应用程序获取文件.根据提供文件的应用程序的实现,可以对来自Base64字符串的字节数组进行gzip压缩.如何识别gzipped数组?我找到了一些方法,但我认为当有人上传zip文件或编写"坏"zip文件时会出错

这是我发现和工作的东西,但它可以以某种方式被利用吗?

C#

public static bool IsGZip(byte[] arr)
{
    return arr.Length >= 2 && arr[0] == 31 && arr[1] == 139;
}
Run Code Online (Sandbox Code Playgroud)

VB.NET

Public Shared Function IsGZip(arr As Byte()) As Boolean
    Return arr.Length >= 2 AndAlso arr(0) = 31 AndAlso arr(1) = 139
End Function
Run Code Online (Sandbox Code Playgroud)

如果IsGzip返回true,我的应用程序将解压缩字节数组.

c# vb.net gzip dotnetzip

8
推荐指数
1
解决办法
1992
查看次数

使用语句和IDisposable接口

将using语句中声明的变量放在一起是因为它们在using块的范围内吗?

我需要这样做:

using (SomeIdisposableImplementation foo = new SomeIdisposableImplementation())
{
    using(SomeIdisposableImplementation2 bar = new SomeIdisposableImplementation2())
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

或者这是否足够,并且"bar"与"foo"一起处理?

using (SomeIdisposableImplementation foo = new SomeIdisposableImplementation())
{
    SomeIdisposableImplementation2 bar = new SomeIdisposableImplementation2();
}
Run Code Online (Sandbox Code Playgroud)

c# vb.net

4
推荐指数
1
解决办法
175
查看次数

标签 统计

c# ×3

vb.net ×2

async-await ×1

dotnetzip ×1

gzip ×1

idisposable ×1