Solved

how to set value in Object[] using C#

Posted on 2008-10-07
5
1,364 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 50 total points
Comment Utility
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
Comment Utility
setvalue starts at index of 0

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

Expert Comment

by:Adecus
Comment Utility
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
Comment Utility
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
Comment Utility
also could be:

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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
asp.net mvc5 3 35
Wpf develop 5 30
Check if number is currency 15 29
XML & .net 5 16
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now