如何添加带循环的项目或用于? [英] How do I add items with a loop or for ?

查看:40
本文介绍了如何添加带循环的项目或用于?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

cKeys.Keyboard = new KeyboardButton [] []

{



new KeyboardButton []

{

新的KeyboardButton(لیستتعرفهها),

新的KeyboardButton(تماسباما),

新的KeyboardButton(نماینده ها)

},



新的KeyboardButton []

{

新的KeyboardButton(راهنما)

}

};



我尝试过:



我如何添加循环项目或用于?

解决方案

你需要列表。



列表< keyboardbutton> keys = new KeyboardButton< keyboardbutton>();



foreach(商品中的商品)

{

键.Add(item);

}



//所以如果你已经填写了密钥列表,那么你可以使用ToArray()对于列表对象



cKeys.Keyboard = keys.ToArry();


简单数组也可以帮助你。< br $>


 KeyboardButton [] keys =  new  KeyboardButton [ 4 ]; 
for int i = 0 ; i < keys.Length; i ++)
{
keys [i] = KeyboardButton();
}


我收到此错误



列表< KeyboardButton> [,] keys =  new 列表< KeyboardButton> [ 2  1 ]; 

键[ 0 0 ] = 列表< KeyboardButton> { 一个};
键[ 1 0 ] = new 列表< KeyboardButton> { two};
cKeys.Keyboard = keys;


错误:
转换类型' System.Collections.Generic .List< Telegram.Bot.Types.KeyboardButton> [*,*]' to ' Telegram.Bot .Types.KeyboardButton [] []' TelegramRobot
-------------------------------- -------------------------------------
KeyboardButton [] keys = new KeyboardButton [ 4 ];
for int i = 0 ; i < keys.Length; i ++)
{
keys [i] = KeyboardButton();
}

cKeys.Keyboard = keys;

错误:
无法隐式转换类型' Telegram.Bot.Types.KeyboardButton []'' Telegram.Bot.Types.KeyboardButton [] []


cKeys.Keyboard = new KeyboardButton[][]
{

new KeyboardButton[]
{
new KeyboardButton("لیست تعرفه ها"),
new KeyboardButton("تماس با ما"),
new KeyboardButton("نماینده ها")
},

new KeyboardButton[]
{
new KeyboardButton("راهنما")
}
};

What I have tried:

how do i add items with a loop or for ?

解决方案

You need a list.

List<keyboardbutton> keys = new KeyboardButton<keyboardbutton>();

foreach(item in items)
{
keys.Add(item);
}

//So if you already filled the list of keys, then you can use ToArray() for the list object

cKeys.Keyboard = keys.ToArry();


Simple array can help you as well.

KeyboardButton[] keys = new KeyboardButton[4];
            for (int i = 0; i < keys.Length; i++)
            {
                keys[i] = new KeyboardButton();
            }


i get this errors

  List<KeyboardButton>[,] keys = new List<KeyboardButton>[2, 1];

            keys[0, 0] = new List<KeyboardButton> { "One" };
            keys[1, 0] = new List<KeyboardButton> { "two" };
            cKeys.Keyboard = keys;


Error : 
convert type 'System.Collections.Generic.List<Telegram.Bot.Types.KeyboardButton>[*,*]' to 'Telegram.Bot.Types.KeyboardButton[][]'	TelegramRobot
---------------------------------------------------------------------
KeyboardButton[] keys = new KeyboardButton[4];
            for (int i = 0; i < keys.Length; i++)
            {
                keys[i] = new KeyboardButton();
            }

            cKeys.Keyboard = keys;

Error : 
Cannot implicitly convert type 'Telegram.Bot.Types.KeyboardButton[]' to 'Telegram.Bot.Types.KeyboardButton[][]


这篇关于如何添加带循环的项目或用于?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆