62,046
社区成员
发帖
与我相关
我的任务
分享
List<string[]> list = new List<string[]>()
{ new string[]{"AA","BB"} ,
//new string[]{"BB","AA"} ,话说这样在数据库里不是一样的么,like查询时
new string[]{"BB"} ,
new string[]{"BB"} ,
};
StringBuilder sql = new StringBuilder();
foreach (var arr in list)
{
if (sql.Length > 0)
{
sql.AppendLine("union");
}
sql.Append("select * from table where ");
for (var i = 0; i < arr.Length; i++)
{
if (i > 0)
{
sql.Append(" And ");
}
sql.Append(" title like %'" + arr[i] + "%'");
}
}
//
// 摘要:
// 通过使用指定的 System.Collections.Generic.IEqualityComparer<T> 对值进行比较返回序列中的非重复元素。
//
// 参数:
// source:
// 要从中移除重复元素的序列。
//
// comparer:
// 用于比较值的 System.Collections.Generic.IEqualityComparer<T>。
//
// 类型参数:
// TSource:
// source 中的元素的类型。
//
// 返回结果:
// 一个 System.Collections.Generic.IEnumerable<T>,包含源序列中的非重复元素。
//
// 异常:
// System.ArgumentNullException:
// source 为 null。
public static IEnumerable<TSource> Distinct<TSource>(this IEnumerable<TSource> source, IEqualityComparer<TSource> comparer);
class Program
{
static void Main(string[] args)
{
List<string> list = new List<string>() { "a", "b", "c" };
bind(list, new List<string>(), 1);
Console.ReadLine();
}
private static void bind(List<string> list, List<string> source, int count)
{
if (source.Count <= count)
{
if (source.Count > 1)
Write(source);
}
for (int i = 0; i < list.Count; i++)
{
if (source.Contains(list[i].Trim()))
continue;
source.Add(list[i]);
bind(list, source, count + 1);
source.Remove(list[i]);
}
}
private static void Write(List<string> List)
{
for (int i = 0; i < List.Count; i++)
{
Console.Write(List[i]);
}
Console.Write("\n");
}
}
这样的结果是:这样的结果会有ab ba , abc cba这样的结果,这样要怎么把它有ab 就不给他ba,有abc 就不给他cba 和bca之类的