小编swi*_*tor的帖子

使用语句和等待关键字在c#中很好地发挥作用

我有一种情况,我正在async调用返回和IDisposable实例的方法.例如:

HttpResponseMessage response = await httpClient.GetAsync(new Uri("http://www.google.com"));
Run Code Online (Sandbox Code Playgroud)

现在async,在使用IDisposable实例之前,使用"response"变量的调用和代码将包含在using语句中.

我的问题是,当async混合中抛出关键字时,这仍然是正确的方法吗?即使代码编译,using语句是否仍然可以在下面的示例中按预期工作?

例1

using(HttpResponseMessage response = await httpClient.GetAsync(new Uri("http://www.google.com")))
{
    // Do something with the response

    return true;
}
Run Code Online (Sandbox Code Playgroud)

例2

using(HttpResponseMessage response = await httpClient.GetAsync(new Uri("http://www.google.com")))
{
    await this.responseLogger.LogResponseAsync(response);

    return true;
}
Run Code Online (Sandbox Code Playgroud)

c# asynchronous using-statement

96
推荐指数
1
解决办法
1万
查看次数

"count ++"在C#中返回什么?

刚碰到一些没有按我认为应该做的代码.其他人认为这应该返回1吗?有没有一个很好的解释为什么它不?

int count = 0;

count++.ToString(); // Returns 1 no?
Run Code Online (Sandbox Code Playgroud)

我一直以为count ++与count = count + 1相同......

c#

18
推荐指数
3
解决办法
5876
查看次数

iphone低通滤波器

我正在尝试为iphone应用程序实现一个低通滤波器,在那里我录制一个声音,然后它会被轻微闷声播放; 就像声音来自另一个房间.

我已经研究了音频录制和操作的不同选项,并且发现它有点令人困惑......数字信号处理根本不是一个强点.我主要研究OpenAL,在EFX库中有一个专门做我需要的过滤器,但是iPhone上没有包含EFX.有没有办法使用OpenAL为iPhone复制这种行为?是否有其他选项,如音频单元可以提供解决方案?

谢谢你的帮助

编辑:

所以在Tom的回答和链接之后,我想出了我认为正确的实现.但是,我根本没有得到消声效果,而只是减少音量.这是我目前的(汇总)代码:

使用AVAudioRecorder和以下设置记录文件:

[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];

[recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
Run Code Online (Sandbox Code Playgroud)

然后我读入文件并使用以下代码对其进行转换:

// Read in the file using AudioFileOpenURL
AudioFileID fileID = [self openAudioFile:filePath];

// find out how big the actual audio data is
UInt32 fileSize = [self audioFileSize:fileID];

// allocate the memory to hold the file
SInt16 * outData = (SInt16 *)malloc(fileSize); 

// Read …
Run Code Online (Sandbox Code Playgroud)

iphone signal-processing openal filter

13
推荐指数
2
解决办法
5434
查看次数

在C#对象结构中连接字符串

我有一个如下所示的对象结构:

var Results = new List<ResultObj>()
    {
        new ResultObj()
        {
            Messages = new List<MessageObj>()
            {
                new MessageObj()
                {
                    Message = "message 1"
                },
                new MessageObj()
                {
                    Message = "message 2"
                }
            }
        },
        new ResultObj()
        {
            Messages = new List<MessageObj>()
            {
                new MessageObj()
                {
                    Message = "message 3"
                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

如何使用LINQ或其他C#方法获取单个字符串,并将所有Message值连接在一起?像下面的东西

"消息1,消息2,消息3"

谢谢!

c# linq

4
推荐指数
2
解决办法
696
查看次数