如何将Int32转换为对象

如何将Int32转换为对象

本文介绍了如何将Int32转换为对象[]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助:怎么做-

Pls help: how to do this-

Int32 UserID;

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


---


---

Error: Cannot implicitly convert type 'int[]' to 'object[]'

推荐答案

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







or

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



就个人而言,我更喜欢第二个选项.



Personally, i prefer the 2nd option.


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);
}


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


:)


这篇关于如何将Int32转换为对象[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:05