Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Object Array Method Return Type

  Asked By: Eve    Date: Nov 24    Category: Sharepoint    Views: 1248

I want (well I have already started to) create a method that is off
some type of string array BUT I want it to be an object instead of primitive
type so I can check for nulls I have not really spent a lot of time doing this,
I want it to be some what generic, maybe something from the iCollections, or
generic class would fit the bill, but I want it to be generic and simple don't
want to over kill it! Here is what I wrote thus far but it is throwing a new
object error out:

private Object[] _mtd_GetListItems(string _lcl_ListName, string
_lcl_ListColumnName)
{
Object _data_Value = null;
Object[] _data_Array = null;

if (string.IsNullOrEmpty(_lcl_ListName) ||
string.IsNullOrEmpty(_lcl_ListColumnName))
{}
else
{
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists[_lcl_ListName];
SPListItemCollection items = list.Items;

int count = 0;
foreach (SPListItem item in items)
{
if (true)
{
_data_Value = item[_lcl_ListColumnName];

if (_data_Value == null)
{ }
Else

//////////////////This is where the error happens for me "New object reference
error"/////////////////////////////////////

{ _data_Array[count] = _data_Value; }


count++;
}
}
}
return _data_Array;
}

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Bhupendra Borkar     Answered On: Nov 24

I greatly appreciate all the responses I got
exactly what I wanted!! The final solution I decided to go with was to use an
ArrayList from the system.collections because it was the quickest & easiest for
me to implement (I was torn between this and Dean's, his was a good match as
well, I think I will stick that snippet into my code bank for later) I am
posting the end results for any who is interested to see how the code turned
out:

The calling CODE looks like this:
////////////////////////////////////////////////////////////////////////////////\
//

ArrayList items = new ArrayList(_mtd_GetListItems(_ListName,_ListColumn));

if (items != null)
{
foreach (Object item in items)
{
if (string.IsNullOrEmpty(item.ToString()))
{

////////////////////////////////////////////////////////////////////////////////\
//

Final METHOD:

private ArrayList _mtd_GetListItems(string _lcl_ListName, string
_lcl_ListColumnName)
{
Object _data_Value = null;
ArrayList _data_Array = new ArrayList();

if (string.IsNullOrEmpty(_lcl_ListName) ||
string.IsNullOrEmpty(_lcl_ListColumnName))
{}
else
{
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists[_lcl_ListName];
SPListItemCollection items = list.Items;

foreach (SPListItem item in items)
{
_data_Value = item[_lcl_ListColumnName];

if (_data_Value == null)
{ }
else
{ _data_Array.Add(_data_Value); }
}
}
return _data_Array;
}

 
Didn't find what you were looking for? Find more on Object Array Method Return Type Or get search suggestion and latest updates.




Tagged: