Array 2D : Array Util « Collections Data Structure « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » Collections Data Structure » Array UtilScreenshots 
Array 2D
  
//http://calcsharp.codeplex.com/license
//Microsoft Public License (Ms-PL)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace CalcSharp.Core.Containers
{
    public class Array2D<Type>
    {
        Type[] data;
        int rows, cols;

        public Array2D(int Rows, int Columns)
        {
            if (Rows < 0throw new ArgumentException("Rows must be a positive number");
            if (Columns < 0throw new ArgumentException("Columns must be a positive number");
            this.rows = Rows;
            this.cols = Columns;
            this.data = new Type[Rows * Columns];
        }

        public Array2D(Type[,source)
        {
            this.rows = source.GetLength(0);
            this.cols = source.GetLength(1);
            this.data = new Type[rows * cols];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    this.data[j * rows + i= source[i, j];
                }
            }
        }

        public void InsertArrayAsRow(Type[] Array, int Rowindex)
        {
            int limit = this.Columns;
            if (Rowindex > this.Rows || Rowindex < 0throw new ArgumentException("Rowindex must be in range: [0 -> rows count]");
            if (Array.Length <= this.Columnslimit = Array.Length;
            for (int i = 0; i < limit; i++this[Rowindex, i= Array[i];
        }

        public void InsertArrayAsColumn(Type[] Array, int Columnindex)
        {
            int limit = this.Rows;
            if (Columnindex > this.Columns || Columnindex < 0throw new ArgumentException("Columnindex must be in range: [0 -> columns count]");
            if (Array.Length <= this.Rowslimit = Array.Length;
            for (int i = 0; i < limit; i++this[i, Columnindex= Array[i];
        }

        public Type this[int Row, int Column]
        {
            get return data[Column * rows + Row]}
            set data[Column * rows + Row= value; }
        }

        public int Rows
        {
            get return rows; }
        }

        public int Columns
        {
            get return cols; }
        }

        public int Length
        {
            get return cols * rows; }
        }

        public Type[,ToArray()
        {
            Type[,array = new Type[this.rows, this.cols];
            for (int i = 0; i < this.cols; i++)
            {
                for (int j = 0; j < this.rows; i++)
                {
                    array[i, j= data[j * rows + i];
                }
            }
            return array;
        }
    }
}

   
    
  
Related examples in the same category
1.Return the average of the given values
2.Return the percentage of a given value.
3.return the min value in the list of double
4.return the max value in the list of double
5.Returns a string representation of the sbyte array
6.Returns a string representation of the char array
7.Returns a string representation of the double array
8.Returns a string representation of the float array
9.Returns a string representation of the int array
10.Returns a string representation of the long array
11.Returns a string representation of the object array
12.Returns a string representation of the short value array
13.Returns a string representation of the bool value array
14.Ensures that the sbyte array cannot hold more than maxCapacity elements.
15.Ensures that the char array cannot hold more than maxCapacity elements.
16.Ensures that the double array cannot hold more than maxCapacity elements.
17.Ensures that the float array cannot hold more than maxCapacity elements.
18.Ensures that the int array cannot hold more than maxCapacity elements.
19.Ensures that the long array cannot hold more than maxCapacity elements.
20.Ensures that the object array cannot hold more than maxCapacity elements.
21.Ensures that the short array cannot hold more than maxCapacity elements.
22.Ensures that the bool array cannot hold more than maxCapacity elements.
23.Copy an array into another array.
24.Swap two elements in a array
25.Generic Growable Array
26.foreach is used to display the contents of an array of integers.
27.Are two arrays equal.
28.Are thos two arrays having the save contents
29.Convert object array to string
30.Get array size
31.Convert array content to generic type array
32.Searches for the specified object and returns the index of the first occurrence within the entire one-dimensional System.Array.
33.Creates a new array with just the specified elements.
34.Get a array of object from a enum datatype.
35.Reinitializes an int array to the given value in an optimized way: intArraySet
36.Returns a Boolean indicating whether the Array is Empty (is Null or has a length of zero).
37.Places elements from an enumerable into an array.
38.Bit Array 2D
39.Counting the distribution of the values in an array.
40.Collection of static methods for operations on arrays
41.Char Array Writer
42.Computes the indices
43.Compare Array
44.Remove element from Array
45.Concatenate Array
46.Get the array slice between the two indexes
47.Find subarray in the source array.
48.Check if the array contains needle on specified position
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.