I'm converting an old classic ASP method for data logging. One of the parameters could be an Array or a string. What type of variable do I declare? I tried declaring it as an object, and then testing the to see if it is an array. However, I cant seem to parse out the array contents (Should be a simple string array).
Here is a snippet of the classic ASP code:
Public function security(u,a,d)
' -------------------------------------------------------
' Write to tbl_log_security, returning a 1-Pass or 0-Fail
' -------------------------------------------------------
u = u + 0
af = u
if len(request.Cookies("userid")) > 0 then af = request.Cookies("userid")
security = 1 ' Success
Dim objCommandLog
Set objCommandLog = Server.CreateObject("ADODB.Connection")
objCommandLog.open = application("connVRVprimary")
Err.Clear
if isarray(d) then
for I = 0 to ubound(d)
strDetails = strDetails & chr(13) & "Detail " & I & ": " & d(i) & " "
next
elseif len(d) > 0 then : strDetails = d & " "
end if
And here how I thought it might be converted to C#.
public static bool security(string UserID, string Action, object Details )
{
// Apparently, Details can be a string or an array !
// UserID is passed in as a string, we need to convert it to an int
Int32 iUserID; //af
string strDetails;
if (!Int32.TryParse(UserID, out iUserID))
{
//If it doesn't convert, then use the UserID from Application Object
iUserID = Convert.ToInt32(ApplicationObject.USERID);
}
Type valueType = Details.GetType();
if (valueType.IsArray)
{
for(int i = 0, i < Details.Length; i++)
{
strDetails += "Detail " + i + ": " + Details(i);
}
}
else
{ // is string
strDetails = Details;
}
Intellisense is telling me that I can't get the length property or iterate through it. I suspect that even thought it might come in as an array, it is treated as an object. Any help would be appreciated.