C#如何使这[[string,int],[string,int]]

时间:2015-12-07 16:47:17

标签: c# arrays

我有两个阵列:

  1. String of String
  2. Numbners数组
  3. 在输出上我需要一个数组数组,其数组中包含Stringint

    像这样:

    [
      [string, int],
      [string, int],
      [string, int],
    ]
    

1 个答案:

答案 0 :(得分:0)

您可以使用LINQ's Zip执行此操作。

public class HomePage extends AppCompatActivity {

    private GestureDetectorCompat gestureDetectorCompat;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_page);

        gestureDetectorCompat = new GestureDetectorCompat(this, new MyGestureListener());
    }

    @Override
    public boolean onTouchEvent (MotionEvent event) {
        this.gestureDetectorCompat.onTouchEvent(event);
        return super.onTouchEvent(event);
    }

    class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
        //handle 'swipe up' action only

        @Override
        public boolean onFling(MotionEvent event1, MotionEvent event2,
                               float velocityX, float velocityY){

            /*
            Toast.makeText (getBaseContext(),
            event1.toString() + "\n\n" +event2.toSting(),
            Toast.LENGTH_SHORT).show();
             */

            if (event2.getX() < event1.getX()){
                Toast.makeText(getBaseContext(),
                        "Swipe Up - startActivity()",
                        Toast.LENGTH_SHORT).show();

            //switch another activity
                Intent intent = new Intent(
                        HomePage.this, New_Page.class);
                startActivity(intent);
            }

                return true;
            }
        }
    }

结果

var strings = new[] { "a", "b", "c" };
var ints = new[] { 1, 2, 3 };
var result = strings.Zip(ints, (s, i) => new object[] { s, i });
Console.WriteLine(string.Join(", ", result.Select(x => "{ " + string.Join(", ", x) + " }")));