无法将类型“System.Collections.Generic.List”隐式转换为“int”

lianqiyi9063 2016-10-23 11:13:08
运行时出这个错,求大神指点如何解决
...全文
1180 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoruanzhu 2016-10-25
  • 打赏
  • 举报
回复 1
太着急了, 改成 public int[] lat() 最后的函数返回值 return result;
xiaoruanzhu 2016-10-25
  • 打赏
  • 举报
回复 1
public int lat() 改成 public List<int> lat(0
lianqiyi9063 2016-10-24
  • 打赏
  • 举报
回复
我的思路是求出一个数组中的最大值的数组下标,并且用button输出,然后再弄一个button输出这个数组中比最大值小于3以内的数组的下标,再敷给一个动态数组,在visual studio窗体中输出 求代码
lianqiyi9063 2016-10-24
  • 打赏
  • 举报
回复
但是运行还是不成功啊
hwj19900904 2016-10-24
  • 打赏
  • 举报
回复
类型不一样,肯定不能转啊
EnForGrass 2016-10-24
  • 打赏
  • 举报
回复
引用 8 楼 lianqiyi9063 的回复:
但是运行还是不成功啊
自己要学会解决问题,不然怎么提高技术,况且你这个小需求很简单
EnForGrass 2016-10-23
  • 打赏
  • 举报
回复
引用 6 楼 lianqiyi9063 的回复:
但是我是想返回得到的这个数组啊!那我应该怎么改呢
改一下 public int[] lat()
lianqiyi9063 2016-10-23
  • 打赏
  • 举报
回复
但是我是想返回得到的这个数组啊!那我应该怎么改呢
threenewbee 2016-10-23
  • 打赏
  • 举报
回复
int x = list[n] 不能 int x = list
EnForGrass 2016-10-23
  • 打赏
  • 举报
回复
public int lat() { int[] array = new int[] { 9, 2, 5, 4, 14, 6, 9, 7, 8, 5, 6 }; int temp = 0; int index = 0; for (int i = 0; i < array.Length; i++) { if (temp < array[i]) //如果用<= 则找到的是最大值(多个中的最后一个) <则是多个中的第一个 { temp = array[i]; index = i; } List<int> list = new List<int>(); for (int x = 0; x < array.Length; i++) { if (array[x] + 3 > array[index]) list.Add(int.Parse(currentline)); ; } int[] result = list.ToArray(); return list; } 红色部分所在函数,应该返回int,你却返回List<int>
lianqiyi9063 2016-10-23
  • 打赏
  • 举报
回复
c#新手,求指点 还有 list.Add(int.Parse(currentline)); ;这个里面的currentline不明白应该填什么
lianqiyi9063 2016-10-23
  • 打赏
  • 举报
回复
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Collections; namespace WindowsFormsApplication6 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public int getnumber() { int[] array = new int[] { 9, 2, 5, 4, 14, 6, 9, 7, 8, 5, 6 }; int temp = 0; int index = 0; for (int i = 0; i < array.Length; i++) { if (temp < array[i]) //如果用<= 则找到的是最大值(多个中的最后一个) <则是多个中的第一个 { temp = array[i]; index = i; } } return index; } private void button1_Click_1(object sender, EventArgs e) { textBox1.Text = getnumber().ToString(); } private void textBox1_TextChanged(object sender, EventArgs e) { } public int lat() { int[] array = new int[] { 9, 2, 5, 4, 14, 6, 9, 7, 8, 5, 6 }; int temp = 0; int index = 0; for (int i = 0; i < array.Length; i++) { if (temp < array[i]) //如果用<= 则找到的是最大值(多个中的最后一个) <则是多个中的第一个 { temp = array[i]; index = i; } List<int> list = new List<int>(); for (int x = 0; x < array.Length; i++) { if (array[x] + 3 > array[index]) list.Add(int.Parse(currentline)); ; } int[] result = list.ToArray(); return list; } } } }
EnForGrass 2016-10-23
  • 打赏
  • 举报
回复
说的很明白了啊,你贴出你的代码来看看

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧