Click here to Skip to main content
15,903,033 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Pls help: how to do this-

C#
Int32 UserID;

object[] parameters = new[] { UserID };

---

C#
Error: Cannot implicitly convert type 'int[]' to 'object[]'
Posted
Updated 5-Sep-11 4:37am
v2

VS is deriving the type of the array from the type of the variable used in its creation (in this case userID), there are 2 ways around this, either:

C#
object[] parameters = new[] { (object)UserID };


or

C#
object[] parameters = new object[] { UserID };


Personally, i prefer the 2nd option.
 
Share this answer
 
Here's some ideas for you:
XML
private Int32 UserID;
private Int32 AdminID;
private List<Int32> ListOInt32s;
private List<object> ListOObjects;

private void MakeIDS(Int32 uID, Int32 aID)
{
    UserID = uID;
    AdminID = aID;

    // anonymous type
    // exists only in the scope of this method call
    var IDS = new {UserID, AdminID};

    // generic strongly typed
    ListOInt32s = new List<Int32> {UserID, AdminID};

    // generic typed as Object
    ListOObjects = new List<object> {UserID, AdminID};
}

private void button1_Click(object sender, EventArgs e)
{
    MakeIDS(4,5);
}
 
Share this answer
 
v3
It might be helpful,

C#
static void Main(string[] args)
{
    Int32 one = 1, two = 2;
    object[] myArray = { one, two };
}

:)
 
Share this answer
 
Thanks all.
I did it using Permalink GParkings solution.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900