小编Ras*_*org的帖子

打破parallel.foreach?

如何打破parallel.for循环?

我有一个非常复杂的声明,如下所示:

Parallel.ForEach<ColorIndexHolder>(ColorIndex.AsEnumerable(),
    new Action<ColorIndexHolder>((ColorIndexHolder Element) =>
    {
        if (Element.StartIndex <= I && Element.StartIndex + Element.Length >= I)
        {
            Found = true;
            break;
        }
    }));
Run Code Online (Sandbox Code Playgroud)

使用并行类,我可以到目前为止优化这个过程.然而; 我无法弄清楚如何打破并行循环?该break;语句抛出以下语法错误:

没有封闭的环可以打破或继续

c# parallel-processing multithreading parallel.foreach

95
推荐指数
5
解决办法
5万
查看次数

使用'goto'语句不好吗?

在做了一些关于如何突破二次循环的研究之后

while (true) { // Main Loop
   for (int I = 0; I < 15; I++) { // Secondary loop
       // Do Something
       break; // Break main loop?
   }
}
Run Code Online (Sandbox Code Playgroud)

大多数人建议调用'goto'函数
看如下例:

while (true) { // Main Loop
   for (int I = 0; I < 15; I++) { // Secondary Loop
       // Do Something
       goto ContinueOn; // Breaks the main loop
   }
}
ContinueOn:
Run Code Online (Sandbox Code Playgroud)

然而; 我经常听说'goto'声明是不好的做法.下图完美地说明了我的观点: 系列发现

所以

  • goto语句真的有多糟糕,为什么?
  • 是否有一种比使用'goto'语句更有效的方法来打破主循环?

c# loops goto break

50
推荐指数
7
解决办法
2万
查看次数

从Google+ API检索个人资料图片

我正在尝试从Google+ API中提取JSON数据.当我包含图像属性时,图像的大小设置为50px.如何更改图像大小?我没有在文档中看到它.https://developers.google.com/+/api/latest/people/get

获取https://www.googleapis.com/plus/v1/people/100300281975626912157?fields=image&key= {YOUR_API_KEY}

响应

{
 "image": {
  "url": "https://lh3.googleusercontent.com/-U353P5vNuRE/AAAAAAAAAAI/AAAAAAAABKM/a7U7bq251x0/photo.jpg?sz=50"
 }
}
Run Code Online (Sandbox Code Playgroud)

google-plus

10
推荐指数
3
解决办法
6787
查看次数

C#中的C++"system()"

我目前正在开发一个C#中的应用程序,它需要像"命令提示符"那样工作,因此我想知道C++是否具有功能

int system ( const char * command ); 
Run Code Online (Sandbox Code Playgroud)

cstdlib在C#中存在?

还将接受对包含此函数的动态链接库的引用.

c# c++ pinvoke system

5
推荐指数
1
解决办法
3823
查看次数

则DateTime.ToString()?

我遇到了问题.如何正确显示我的日期文本?

使用DateTime.Now我能够接收计算机时钟设置为当前的日期和时间,但是,当我尝试解析为字符串格式时,它还显示日期:12-04-2012 12:38 我试图只获得时间字符串,仅限12:38

到目前为止我尝试过的是 Console.WriteLine(DateTime.Now.ToString("00:00:00"));

但它不起作用= /

c# string parsing date

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

试图从VB 6调用C#COM对象

我试图从VB 6调用C#COM对象,我收到一个错误:453说很难找到DLL的入口点.我把c#中的所有模块都设为public,我的COM可见性为TRUE,我注册了我的.dll文件,我有Type库文件可用,我也调用了P/Invoke调用.我仍然得到错误.我在下面粘贴我的代码

VB6:

Private Declare Function DisplayCForm Lib "C:\Users\LP027077\Documents\Visual Studio 2010\Projects\COMWorld\COMWorld\bin\Debug\COMWorld.dll" ()
Private Sub Command1_Click()
DisplayCForm
End Sub
Run Code Online (Sandbox Code Playgroud)

C#:

 namespace COMWorld
{

    [Guid("23047247-38D3-464F-A845-0D42A7ACD622")]
    [ComVisible(true)]
    public class COMObject
    {
        [DllImport("Kernel32.dll", EntryPoint = "GetConsoleWindow",SetLastError = true)]
        internal static extern IntPtr GetConsoleWindow();
        public void COMModule()
        {
            Form f1 = new Form();
            f1.Text = "Hello VB6 from c# .NET";
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

请帮帮我这方面!! 提前致谢

c# vb6

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

C++公共语言运行时支持[.Net?]

嗨,大家好!
这不是一个大问题,但是,我想知道当你启用选项"公共语言运行时支持(/ clr)"时它是否需要".net框架"?

c++ clr c++-cli

0
推荐指数
1
解决办法
1245
查看次数

返回int,API时Pinvoke


我目前遇到一个从C#windows应用程序调用Win32 DLL [Native]的问题.

我到目前为止.

C++源码:

extern "C" __declspec(dllexport) int PlaceSound(__in DWORD frequence, __in DWORD duration)
{
    Beep(frequence, duration);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

C#来源:

[DllImport("SampleLib.dll")]
    public extern static int PlaceSound(int Freq, int Dura);

 public form1 { InitializeComponements; PlaceSound(150, 500); }
Run Code Online (Sandbox Code Playgroud)

在调试时,我接收到声音,但是,当库返回其整数值时,我似乎得到了一个pinvoke.

Pinvoke:
调用PInvoke函数'SoundTracer!SoundTracer.Form1 :: PlaceSound'使堆栈失衡.这很可能是因为托管PInvoke签名与非托管目标签名不匹配.检查PInvoke签名的调用约定和参数是否与目标非托管签名匹配.

我究竟做错了什么?

c# c++ api pinvoke

0
推荐指数
1
解决办法
847
查看次数

为什么我必须在String.Length更新之前终止我的语句

在先前拆分的语句中使用string.Length属性时,除非语句终止,否则它似乎返回ArgumentOutOfRangeException.

考虑一下:

// Throw exception?
var X = "[Hello World. This is a test]";
X = X.Split('[')[1].Split(']')[0].Remove(0, X.Length - 1);
Run Code Online (Sandbox Code Playgroud)

与不允许任何例外的半冒号一起终止声明.

// Works perfectly fine
var X = "[Hello World. This is a test]";
X = X.Split('[')[1].Split(']')[0];
X = X.Remove(0, X.Length - 1);
Run Code Online (Sandbox Code Playgroud)

为什么我必须终止Length的语句以返回字符串的正确长度?

c# string

0
推荐指数
1
解决办法
28
查看次数