Advertisement
Guest User

Untitled

a guest
Oct 16th, 2014
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. class Matrix
  2. {
  3. double[] matrix;
  4.  
  5. int col;
  6. int row;
  7.  
  8. public Matrix(int row,int col)
  9. {
  10. this.row = row;
  11. this.col = col;
  12. matrix = new double[row * col];
  13. }
  14.  
  15. public int Width { get { return col; } }
  16. public int Height { get { return row; } }
  17.  
  18. public double this[int row,int col]
  19. {
  20. get { return matrix[row * Width + col]; }
  21. set { matrix[row * Width + col] = value; }
  22. }
  23.  
  24. public override string ToString()
  25. {
  26. StringBuilder builder = new StringBuilder();
  27. for(int i = 0; i < Width;i++)
  28. {
  29. for(int j = 0;j < Height;j++)
  30. {
  31. builder.AppendFormat("{0}\t",this[i,j]);
  32. }
  33. builder.AppendLine();
  34. }
  35. return builder.ToString();
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement