Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to set value in Object[] using C#

Posted on 2008-10-07
5
Medium Priority
?
1,381 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 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

730 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