手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#组合函数的使用详解
C#组合函数的使用详解
摘要:如下所示:复制代码代码如下:usingSystem;usingSystem.Collections.Generic;usingSystem....

如下所示:

复制代码 代码如下:

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Class1

{

static string[] str = { "A", "B", "C", "D", "E" };

static void Main()

{

Dictionary<string, int> dic = new Dictionary<string, int>();

//将数组元素添加到dic

for (int i = 0; i < str.Length; i++)

{

dic.Add(str[i], i);

}

GetDic(dic);

Console.ReadLine();

}

static void GetDic(Dictionary<string, int> dd)

{

Dictionary<string, int> dic = new Dictionary<string, int>();

//主要是抓住AB,AC,AD,AE,然后就是开始从 BC,BD这样的原理用dd中的键与数组的中对应索引比dd中的value大进行组合

foreach (KeyValuePair<string, int> kk in dd)

{

for (int i = kk.Value + 1; i < str.Length; i++)

{

Console.WriteLine(kk.Key + str[i]);

dic.Add(kk.Key + str[i], i);

}

}

//递归

if (dic.Count > 0) GetDic(dic);

}

}

}

结果

AB

AC

AD

AE

BC

BD

BE

CD

CE

DE

ABC

ABD

ABE

ACD

ACE

ADE

BCD

BCE

BDE

CDE

ABCD

ABCE

ABDE

ACDE

BCDE

ABCDE

【C#组合函数的使用详解】相关文章:

c#数组详解

c#之利用API函数实现动画窗体的方法详解

浅析C# 基础语法的使用

.Net笔记:System.IO之Stream的使用详解

C# Word 类库的深入理解

C#多维数组学习使用

c#中DateTime.Now函数的使用详解

c# Base关键字的使用

C#注释的一些使用方法浅谈

C#方法的总结详解

精品推荐
分类导航