Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1443
  • Last Modified:

how to set value in Object[] using C#

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
Vivek Thangaswamy
Asked:
Vivek Thangaswamy
4 Solutions
 
Priest04Commented:
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
 
CAnuszczykCommented:
setvalue starts at index of 0

object[] argList = new object[8];
0
 
AdecusCommented:
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
 
Jaime OlivaresSoftware ArchitectCommented:
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
 
Jaime OlivaresSoftware ArchitectCommented:
also could be:

object[] argList = new object[] { documentLibraryGUID, "", "", "", "", QueryOptions, webId };
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now