int[] ary = { 0, 1 }; var source = from t1 in ary from t2 in ary from t3 in ary select new { s = "" + t1 + t2 + t3 }; foreach (var t in source) Console.WriteLine(t.s);
这个用二进制就可以了。 using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace ConsoleApplication1 { class Program { static void Main(string[] args) { char first = '0', second = '1'; for (int i = 0; i < 8; i++) { string r = ""; for (int j = 0; j < 3; j++) { if ((i >> j) % 2 == 0) r += first; else r += second; } Console.WriteLine(r); } } } }000 100 010 110 001 101 011 111 Press any key to continue . . .
int[] ary = { 0, 1 };
var source = from t1 in ary from t2 in ary from t3 in ary select new { s = "" + t1 + t2 + t3 };
foreach (var t in source)
Console.WriteLine(t.s);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
char first = '0', second = '1';
for (int i = 0; i < 8; i++)
{
string r = "";
for (int j = 0; j < 3; j++)
{
if ((i >> j) % 2 == 0) r += first; else r += second;
}
Console.WriteLine(r);
}
}
}
}000
100
010
110
001
101
011
111
Press any key to continue . . .