2016-08-28 7 views
0

私はPythonプロジェクトをC#に移植しています。PythonをC#に移植する - どのようにタプルをタプル上で反復処理できますか?

これまで私はこの問題に遭遇しました。これをC#に移植する方法はありますか?私はこれを試してみた

verts = (-1,-1,-1),(1,-1,-1),(1,1,-1),(-1,1,-1),(-1,-1,1),(1,-1,1),(1,1,1),(-1,1,1) 
edges = (0,1),(1,2),(2,3),(3,0),(4,5),(5,6),(6,7),(7,4),(0,4),(1,5),(2,6),(3,7) 

for edge in edges: 
    for x,y,z in (verts[edge[0]],verts[edge[1]]): 
     [...] 

verts.Add(new List<string> { "-1,-1,-1" }); 
verts.Add(new List<string> { "1,-1,-1" }); 
verts.Add(new List<string> { "1,1,-1" }); 
verts.Add(new List<string> { "-1,1,-1" }); 
verts.Add(new List<string> { "-1,-1,1" }); 
verts.Add(new List<string> { "1,-1,1" }); 
verts.Add(new List<string> { "1,1,1" }); 
verts.Add(new List<string> { "-1,1,1" }); 

edges.Add(new List<string> { "0,1" }); 
edges.Add(new List<string> { "1,2" }); 
edges.Add(new List<string> { "2,3" }); 
edges.Add(new List<string> { "3,0" }); 
edges.Add(new List<string> { "4,5" }); 
edges.Add(new List<string> { "5,6" }); 
edges.Add(new List<string> { "6,7" }); 
edges.Add(new List<string> { "7,4" }); 
edges.Add(new List<string> { "0,4" }); 
edges.Add(new List<string> { "1,5" }); 
edges.Add(new List<string> { "2,6" }); 
edges.Add(new List<string> { "3,7" }); 

foreach (List<string> vert in verts) 
     { 

      [...] 
     } 

     List<string> lines1 = new List<string>(); 
     List<string> lines2 = new List<string>(); 

     foreach (List<string> edge in edges) 
     { 
      int edge1 = int.Parse(edge[0].Split(',')[0]); 
      int edge2 = int.Parse(edge[0].Split(',')[1]); 

      int x; 
      int y; 
      int z; 

      foreach (int vert in verts[edge1]) 
      { 
       [...] 
      } 
     } 

をだから今、私は非常に混乱して取得しています、多くのバグの、ここにあり。 私は複雑で実用的ではないようです。

は、私は再びちょうどコメントを残して、誰かが私を助けることができます:)

あなたはそれを読み取ることが難しい場合は、単に、コメントを残して、任意のより多くの情報が必要な場合は願っています。私から

〜Coolq

答えて

1

これは、あなたがそれをやって行くことができる一つの方法です...

 var verts = new[] 
     { 
      new Tuple<int,int,int> (-1,-1,-1), 
      new Tuple<int,int,int> (1,-1,-1), 
      new Tuple<int,int,int> (1,1,-1), 
      new Tuple<int,int,int> (-1,1,-1), 
      new Tuple<int,int,int> (-1,-1,1), 
      new Tuple<int,int,int> (1,-1,1), 
      new Tuple<int,int,int> (1,1,1), 
      new Tuple<int,int,int> (-1,1,1) 
     }; 
     var edges = new[] 
     { 
      new Tuple<int,int>(0,1), 
      new Tuple<int,int>(2,2), 
      new Tuple<int,int>(2,3), 
      new Tuple<int,int>(3,0), 
      new Tuple<int,int>(4,5), 
      new Tuple<int,int>(5,6), 
      new Tuple<int,int>(6,7), 
      new Tuple<int,int>(7,4), 
      new Tuple<int,int>(0,4), 
      new Tuple<int,int>(1,5), 
      new Tuple<int,int>(2,6), 
      new Tuple<int,int>(3,7) 
     }; 

     foreach(var edge in edges) 
     { 
      var edge1 = edge.Item1; 
      var edge2 = edge.Item2; 

      int x, y, z;//not sure why you need these? 

      foreach(var vert in new[] { verts[edge1].Item1, verts[edge1].Item2, verts[edge1].Item3 }) 
      { 
       //[...] 
      } 
     } 
+0

あなたがこのに時間と労力を入れている明確である、1 :) また、それは非常にきれいで明確です。だからそれもチェックです;) –

関連する問題