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

  • Home
  • SEARCH
  • 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 6781041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:34:39+00:00 2026-05-26T16:34:39+00:00

I am using ExcelDNA/C#/Excel primarily. What I am essentially trying to do is convert

  • 0

I am using ExcelDNA/C#/Excel primarily. What I am essentially trying to do is convert a multi-dimensional array (namely a range of cells) to a singular dimensional array, using the following code:

private static string[] MultiToSingle(object[,] multiArray)
{
   List<string> tempList;
   string[] returnArray;
   tempList = new List<string>();

   //Add each element of the multi-dimensional Array to the list
   foreach (object oneObj in multiArray)
   {
      tempList.Add(oneObj.ToString());
   }
   //Convert the list to a single dimensional array
   returnArray = tempList.ToArray();
   return returnArray;
}

This works a treat, and is used a number of times throughout my project, however I would like to add some more functionality.

When I try to run this function with a range that contains an empty cell, it errors horribly, at the moment I just have a try/catch with an error message informing the user to enter N/A into any empty cells.

What I’d really like to do, is in this function perhaps, convert any ‘null’ or whatever Excel stores empty cells as to the text string “N/A”.

  • 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-05-26T16:34:40+00:00Added an answer on May 26, 2026 at 4:34 pm

    Perhaps just:

    tempList.Add(oneObj == null ? "n/a" : oneObj.ToString());
    

    I can also think of ways to make it more efficient, if you want:

    string[] arr = new string[multiArray.Length];
    int i = 0;
    foreach (object oneObj in multiArray)
    {
        arr[i++] = oneObj == null ? "n/a" : oneObj.ToString();
    }
    return arr;
    

    This cuts out the intermediate list and a few backing array copies.

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

Sidebar

Related Questions

Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using linq2sql I'm trying to take the string in txtOilChange and update the oilChange
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Using Rails 3.2.0 with haml, sass and coffeescript: Basically I am trying to disable
I am trying to evaluate Excel DNA to use it in one of my
I am getting started with developing an Excel-DNA addin using IronPython with some C#
Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for
Using jQuery UI Resizable I'm trying to prevent resizing based on various rules. The
Using delphi 2010, i am wondering if there someway to escape the following string
Using jQuery and jQuery.Colors, I've been trying to come up with a way to

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.