Advertisement
AalborgHTX

Multiarray + foreach

Mar 24th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace WindowsFormsApp16
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void btnKnap_Click(object sender, EventArgs e)
  21.         {
  22.             int[,] min2DimArray = new int[4, 3];
  23.  
  24.             min2DimArray[0, 0] = 20;
  25.             min2DimArray[0, 1] = 22;
  26.             min2DimArray[0, 2] = 21;
  27.  
  28.             min2DimArray[1, 0] = 50;
  29.             min2DimArray[1, 1] = 49;
  30.             min2DimArray[1, 2] = 52;
  31.  
  32.             int temp = 0;
  33.             foreach (int mitelement in min2DimArray)
  34.             {
  35.                 lstUd.Items.Add(mitelement.ToString());
  36.                 temp = temp + mitelement;
  37.             }
  38.  
  39.             lstUd.Items.Add(temp.ToString());
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement