G
G
GroMan_L2022-03-31 22:51:51
C++ / C#
GroMan_L, 2022-03-31 22:51:51

I'm trying to merge 3 arrays into one, what should I do?

Program code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Programm
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        string[] files =

        string[] convert(object sender, EventArgs e)
        {
            string[] files1 = Directory.GetFiles($"{Directory.GetCurrentDirectory()}media", "*.jpg", SearchOption.AllDirectories);
            string[] files2 = Directory.GetFiles($"{Directory.GetCurrentDirectory()}media", "*.png", SearchOption.AllDirectories);
            string[] files3 = Directory.GetFiles($"{Directory.GetCurrentDirectory()}media", "*.jpeg", SearchOption.AllDirectories);
            string[] files12 = files1.Concat(files2).ToArray();
            string[] files = files12.Concat(files3).ToArray();
            return files;
        }


I need to set the string[] files variable to the value of three concatenated arrays in the string[] convert function, but I get errors when calling the function and don't know what to do.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Shipin, 2022-04-01
@alexshipin

As an example

string[] convert() {
  string[] files = Directory.GetFiles(Environment.CurrentDirectory + @"\media", "*.jpg", SearchOption.AllDirectories);
  string[] files2 = Directory.GetFiles(Environment.CurrentDirectory + @"\media", "*.png", SearchOption.AllDirectories);
  string[] files3 = Directory.GetFiles(Environment.CurrentDirectory + @"\media", "*.jpeg", SearchOption.AllDirectories);
  string[] filesAll = new string[files.Length + files2.Length + files3.Length];
  files.CopyTo(filesAll, 0);
  files2.CopyTo(filesAll, files.Length);
  files3.CopyTo(filesAll, files.Length + files2.Length);
  return filesAll;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question