首页 新闻 赞助 找找看

求一个c#函数

0
悬赏园豆:50 [已解决问题] 解决于 2016-12-27 10:13
用于如果符合条件一则输出条件一选项{"hello"},如果符合条件二则输出条件二的选项{"你好"}。
如果都符合则输出条件一和条件二的选项{"hello、你好"}
糯米好吃的主页 糯米好吃 | 初学一级 | 园豆:64
提问于:2016-12-27 09:11
< >
分享
最佳答案
0
string func(List<Tuple<bool,string>> d)
        {
            return string.Join("", d.Where(k => k.Item1).Select(v => v.Item2));
        }

 

收获园豆:50
刘宏玺 | 专家六级 |园豆:14020 | 2016-12-27 09:18

多谢粑粑  但是我想问一下  我想做一个函数名位Create的并实现以上的功能   我刚刚学习c#  很菜勿怪

糯米好吃 | 园豆:64 (初学一级) | 2016-12-27 09:24

@糯米好吃: 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Create(new List<Tuple<bool, string>>() {
                new Tuple<bool, string>(true, "hello"),
                new Tuple<bool, string>(true, "你好"), });

            Console.WriteLine(s);
            Console.ReadKey();
        }

        static string Create(List<Tuple<bool, string>> d)
        {
            return string.Join("", d.Where(k => k.Item1).Select(v => v.Item2));
        }
    }
}
刘宏玺 | 园豆:14020 (专家六级) | 2016-12-27 09:28

@刘宏玺: 我用了一下  果真是不能乱套入啊 

var pdStart = string.Empty;
if (info.PDStartDate.HasValue && info.PDStartDate.Value > DateTime.MinValue)
pdStart = string.Format("腹膜开始({0})", info.PDStartDate.Value.ToString("yyyy-MM-dd"));
var pdEnd = string.Empty;
if (info.PDStopDate.HasValue && info.PDStopDate.Value > DateTime.MinValue)
pdEnd = string.Format("腹膜停止({0})", info.PDStopDate.Value.ToString("yyyy-MM-dd"));
var kt = string.Empty;
if (info.KTDate.HasValue && info.KTDate.Value > DateTime.MinValue)
kt = string.Format("肾移植({0})", info.KTDate.Value.ToString("yyyy-MM-dd"));
lblHDOther.Text = HdisHelper.CreateSummary("、", pdStart, pdEnd, kt);

大师这个是我想要做的代码   这是一段三个选项的字符串代码   还有两个的  苦恼ing  不懂则么改  

糯米好吃 | 园豆:64 (初学一级) | 2016-12-27 09:42

@糯米好吃: 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = CreateSummary("", "你好", string.Empty, "hello");

            Console.WriteLine(s);
            Console.ReadKey();
        }

        static string CreateSummary(string separator, params string[] ss)
        {
            return string.Join(separator, ss.Where(s => !string.IsNullOrEmpty(s)));
        }
    }
}

调用方式不变

刘宏玺 | 园豆:14020 (专家六级) | 2016-12-27 09:52

@刘宏玺: 感激不尽

糯米好吃 | 园豆:64 (初学一级) | 2016-12-27 10:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册