Solved

how to set value in Object[] using C#

Posted on 2008-10-07
5
1,376 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

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

752 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