Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7996821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:48:09+00:00 2026-06-04T14:48:09+00:00

i hav a piece of code in which i have been comparing 2D and

  • 0

i hav a piece of code in which i have been comparing 2D and 1D arrays.. can u please tell me how can i store the results (the elements present in both of the arrays) in another 2D array?
here is the code
i actually want to sav “res” in a new 2D array…

namespace WindowsFormsApplication1strng_cmp
{
    public partial class Form1 : Form
    {
        private static Dictionary<string, Position> BuildDict(string[,] symbols)
        {
            Dictionary<string, Position> res = new Dictionary<string, Position>();
            for (int i = 0; i < symbols.GetLength(0); i++)
            {
                for (int j = 0; j < symbols.GetLength(1); j++)
                {
                    res.Add(symbols[i, j], new Position(i, j));
                }
            }
            return res;
        }

        struct Position
        {
            public int x;
            public int y;
            public Position(int x, int y)
            {
                this.x = x;
                this.y = y;
            }
        }

        private static List<string> CompareUsingBrute(string[] text, string[,] symbols)
        {
            List<string> res = new List<string>();
            for (int x = 0; x < symbols.GetLength(0); x++)
            {
                for (int y = 0; y < symbols.GetLength(1); y++)
                {
                    for (int z = 0; z < text.Length; z++)
                    {
                        if (symbols[x, y] == text[z])
                            res.Add(text[z]);

                    }

                }
            }
            return res;

        }
        string[,] symbols = new string[,] { { "if", "else" }, { "for", "foreach" }, { "while", "do" } };
        string[] text = new string[] { "for", "int", "in", "if", "then" };
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Dictionary<string, Position> dictionary = BuildDict(symbols);
            //   IndexElement[] index = BuildIndex(symbols);

            foreach (string s in CompareUsingBrute(text, symbols))
            {
                listBox2.Items.Add("valid");
            }


        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:48:10+00:00Added an answer on June 4, 2026 at 2:48 pm

    What I understand “from your question” is that you are trying to compare two arrays and storing the common elements –

    Have attached output below as an image-

    class Program
    {
        static void Main(string[] args)
        {
            String[] array1 = {"a","b","c","d","e","f"};
            String[,] array2 = new String[,] {{"a","b","c","d"},{"d","e","f","g"}};
    
            List<String> array1AsList = array1.OfType<String>().ToList();
            List<String> array2AsList = array2.OfType<String>().ToList();
    
            // referring from **Ed S comments below**. Instead of using OFType(...)
            // alternatively you can use the List<>().. ctor to convert an array to list
            // although not sure for 2D arrays
    
            var common = array1AsList.Intersect(array2AsList);
    
        }
    }
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i hav a code like this in the end i m getting error
I hav to save the values of NSUserDefault to the Array,and later on have
i have created a multiple choice question .it hav 3 options in a custom
I have django tinymce setup but I hav noticed an issue with the tool
I hav been going over some old hw assignments from a class last semester.
I hav a code where Include method contains lowerd name of navigation property (Include(descriptions)
I hav been spending some time these days going through gcc internals. I found
I hav a base class which is abstract. I am inheritting a new class
I have a $value such as 22214-HAV.jpg or 22214 HAV.jpg (notice no dash) I
everyone i hav written some code to read images from the Database in C#.net,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.