Programming in almost language

This is the site where you may share your knowledge and experience to eachother..

  • Categories

  • LinkedIn

  • Tweet Me

  • My footsteps

Get the label and corresponding value from matrix C#

Posted by Praveen Kumar on February 20, 2008

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;

public class Class1
    //int row;
    // int col;

    ArrayList labelList = new ArrayList();
    ArrayList valueList = new ArrayList();
    int[,] cell = new int[100, 100];
    string[,] matrix = new string[10, 10];
    //ArrayList matrix = new ArrayList();
    //this function to set the element from matrix
    void setMatrix(int r, int c)
        string ele;

        for (int i = 0; i < r; i++)
            for (int j = 0; j < c; j++)
                Console.WriteLine(“Enter the element at pos:-” + i + “,” + j);
                ele = Console.ReadLine();
                matrix[i, j] = ele;


    //this function to get the element from matrix
    void getMatrix(int r, int c)
        for (int i = 0; i < r; i++)
            for (int j = 0; j < c; j++)
                Console.Write(matrix[i, j] + “\t”);


    //this function to traverse matrix to get the desire item
    void getItem(string item, int r, int c)
        //bool flag=true;
        //Console.WriteLine(“I am inside getItem()”);
        for (int i = 0; i < r; i++)
            for (int k = 0, j = 0; j < c; j++, k++)
                if (item.Equals(matrix[i, j]))
                    //Console.WriteLine(“Yes! u got “+matrix[i, j]+” at position”+i+”,”+j);
                    //Console.WriteLine(“Yes! u got “+matrix[i, j++]+” at position”+i+”,”+j);
                    //valueList.Add(matrix[i, j++]);
                    valueList.Add(matrix[i, k++]);
                    valueList.Add(matrix[i, j]);
        }//end for
        Console.WriteLine(“The Number of item : ” + labelList.Count);

        // Console.WriteLine(valueList.ToString());
    }//end for function getItem()
    void getLabel(ref ArrayList labelList)
        Console.WriteLine(“I am inside getLabelValue”);
        Console.WriteLine(“The Number of item : ” + labelList.Count);
            foreach (object column in labelList)
                // if(column.GetType()==typeof(string))
                Console.WriteLine(“Column : ” + column);
            /*foreach(object value1 in valueList)
               // if(value1.GetType()==typeof(string))
                    Console.WriteLine(“Value : “+value1);
                //Console.WriteLine(“Value is type of : “+value1);*/
        }//end for try
        catch (Exception e)
            Console.WriteLine(“Sorry there is no value!!!!!!! I think this is not column”);
        }//end of tr-catch
        //return labelList;


    static void Main(string[] args)
        ArrayList labelList = new ArrayList();
        int r, c;
        string label, ch;
        Class1 cl = new Class1();
        Console.WriteLine(“Enter row and col”);

        r = Convert.ToInt16(Console.ReadLine());
        c = Convert.ToInt16(Console.ReadLine());
        cl.setMatrix(r, c);
        cl.getMatrix(r, c);
        while (true)
            Console.WriteLine(“Wanna more(Y/N)”);
            ch = Console.ReadLine();
            if (ch.Equals(“Y”))
                Console.WriteLine(“Find the Label/column name : “);
                label = Console.ReadLine();
                cl.getItem(label, r, c);
        }//end of while
        //ArrayList(cl.getLabel(ref labelList));

    }//end of main func



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: