English 中文(简体)
3. 如果情况为c#
原标题:Getting error in Inline if condition in c#
  • 时间:2011-09-07 17:52:34
  •  标签:
  • c#

I am trying to get a string value like below

string bsgrpval;
bsgrpval =
    ConfigurationSettings.AppSettings["Pricing_IncludeALLBaseLineGroup"]=="False"
        ? string.Empty
        : bsgrp.ForEach(x => bsgrpval = bsgrpval + x.Value.ToString() + ",");

我正在经历以下错误:

Type of conditional expression cannot be determined because there is no implicit conversion between string and void

有些人能够帮助我这样做?

问题回答

如果这样的话,你就能够直截了当。 List.ForEach 根本不归还。

condition ? x : y;

<代码>x和y> ,必须交回同一类型(或含蓄)。

也许,你希望有一席之地。

bsgrpval = ConfigurationSettings.AppSettings["Pricing_IncludeALLBaseLineGroup"]=="False"
        ? string.Empty
        : string.Join( , , 
             bsgrp.Select(x => bsgrpval = bsgrpval + x.Value.ToString()).ToArray());

错误发生是因为<代码>。 每一条都有固定回报。 页: 1 Aggregate :

string bsgrpval;  
bsgrpval=ConfigurationSettings.AppSettings["Pricing_IncludeALLBaseLineGroup"] == "False" string.Empty : bsgrp.Aggregate((acc, item) => string.Concat(acc, ",", item.Value.ToString())); 




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签