Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to set value in Object[] using C#

Posted on 2008-10-07
5
Medium Priority
?
1,387 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
5 Comments
 
LVL 18

Assisted Solution

by:Priest04
Priest04 earned 150 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 150 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 600 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 600 total points
ID: 22662762
also could be:

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

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

972 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