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 154343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:57:44+00:00 2026-05-11T09:57:44+00:00

I am still new to C# and I’ve been struggling with various issues on

  • 0

I am still new to C# and I’ve been struggling with various issues on arrays. I’ve got an array of metadata objects (name value pairs) and I would like to know how to create only the number of ‘InputProperty’ objects that I truly need. In this loop I’ve arbitrarily set the number of elements to 20 and I try to bail out when the entry becomes null but the web service on the receiving end of this does not like any null elements passed to it:

private Update BuildMetaData(MetaData[] nvPairs) {     Update update = new Update();     InputProperty[] ip = new InputProperty[20];  // how to make this 'dynamic'     int i;     for (i = 0; i < nvPairs.Length; i++)     {         if (nvPairs[i] == null) break;         ip[i] = new InputProperty();         ip[i].Name = 'udf:' + nvPairs[i].Name;         ip[i].Val = nvPairs[i].Value;     }     update.Items = ip;     return update; } 

In summary, say I only have 3 namevalue pairs in the above input array? Rather than allocate 20 elements for the array called ip, how can code this so ip is only as big as it needs to be. The update object is passed across another webservice so serialization is important (i.e. I can’t use namevaluecollection, etc.).

p.s. Is the only way to followup on a posted question through the ‘add comments’ facility?

  • 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. 2026-05-11T09:57:45+00:00Added an answer on May 11, 2026 at 9:57 am

    If you don’t want to use a List, ArrayList, or other dynamically-sized collection and then convert to an array (that’s the method I’d recommend, by the way), then you’ll have to allocate the array to its maximum possible size, keep track of how many items you put in it, and then create a new array with just those items in it:

    private Update BuildMetaData(MetaData[] nvPairs) {     Update update = new Update();     InputProperty[] ip = new InputProperty[20];  // how to make this 'dynamic'     int i;     for (i = 0; i < nvPairs.Length; i++)     {         if (nvPairs[i] == null) break;         ip[i] = new InputProperty();          ip[i].Name = 'udf:' + nvPairs[i].Name;         ip[i].Val = nvPairs[i].Value;     }     if (i < nvPairs.Length)     {         // Create new, smaller, array to hold the items we processed.         update.Items = new InputProperty[i];         Array.Copy(ip, update.Items, i);     }     else     {         update.Items = ip;     }     return update; } 

    An alternate method would be to always assign update.Items = ip; and then resize if necessary:

    update.Items = ip; if (i < nvPairs.Length) {     Array.Resize(update.Items, i); } 

    It’s less code, but will likely end up doing the same amount of work (i.e. creating a new array and copying the old items).

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

Sidebar

Ask A Question

Stats

  • Questions 70k
  • Answers 70k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer This works (you just need them to be in the… May 11, 2026 at 12:47 pm
  • added an answer It's not actually easy/possible to scroll the list view. You… May 11, 2026 at 12:47 pm
  • added an answer This is the code I used to accomplish exactly what… May 11, 2026 at 12:47 pm

Related Questions

I am still new to sharepoint and would like to know if it is
I am still very new to Ruby (reading through the Pickaxe and spending most
I am new to any scripting language. But, still I worked on scripting a
I am new to any scripting language. But, Still I worked on scripting a
So, I am kinda new to ASP.net development still, and I already don't like
I've been trying to get this code to work for hours! All I need
I am fairly new to Emacs and I have been trying to figure out
I'm trying to develop a little C# application (with MS Visual Express and SQL
I have been trying for a long time to get SQL Server Express on
I need some mind reading here, since I am trying to do what I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.