Solved

how to set value in Object[] using C#

Posted on 2008-10-07
5
1,378 Views
Last Modified: 2013-12-17
how to set value in Object[] using C#

err msg:
{"Object reference not set to an instance of an object."}


object[] argList;
            // error in this line
            argList.SetValue(documentLibraryGUID, 1);
            argList.SetValue(string.Empty, 2);
            argList.SetValue(string.Empty, 3);
            argList.SetValue(string.Empty, 4);
            argList.SetValue(string.Empty, 5);
            argList.SetValue(QueryOptions, 6);
            argList.SetValue(webId, 7);

Open in new window

0
Comment
Question by:Vivek Thangaswamy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 18

Assisted Solution

by:Priest04
Priest04 earned 50 total points
ID: 22662489
You havent initialized objects.


object[] argList = new object[7];


what exactly are you trying to do here. why dont you use List<string>?

Goran
0
 
LVL 2

Assisted Solution

by:CAnuszczyk
CAnuszczyk earned 50 total points
ID: 22662552
setvalue starts at index of 0

object[] argList = new object[8];
0
 
LVL 1

Expert Comment

by:Adecus
ID: 22662738
Also, if you want to dynamically grow your object array you can use an ArrayList:

ArrayList list = new ArrayList();
list.Items.Add(documentLibraryGUID);
list.Items.Add(string.Empty);
list.Items.Add(string.Empty);
list.Items.Add(string.Empty);
list.Items.Add(string.Empty);
list.Items.Add(QueryOptions);
list.Items.Add(webId);

object[] argList = list.ToArray();
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 200 total points
ID: 22662742
it should be:

            object[] argList = new object[7];
            argList.SetValue(documentLibraryGUID, 0);
            argList.SetValue(string.Empty, 1);
            argList.SetValue(string.Empty, 2);
            argList.SetValue(string.Empty, 3);
            argList.SetValue(string.Empty, 4);
            argList.SetValue(QueryOptions, 5);
            argList.SetValue(webId, 6);
0
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 200 total points
ID: 22662762
also could be:

object[] argList = new object[] { documentLibraryGUID, "", "", "", "", QueryOptions, webId };
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question