c# - 此 C# 代码中的错误是什么?
问题描述
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Repeating2
{
class Program
{
static void Main(string[] args)
{
int[] tal = new tal[3];
int tal2 = { 2, 6, 5, 2, 35 };
string str = { "hej", "på", "dig" };
}
}
}
这段代码有什么问题吗?
错误 CS0029 无法将类型 'tal[]' 隐式转换为 'int[]' Repeating2
错误 CS0118 'tal' 是一个变量,但用作类型 Repeating2
错误 CS0622 只能使用数组初始化表达式来分配给数组类型
解决方案
正确的表达方式是这样的
int[] tal = new int[3]; // new required data type (tal isn't)
int[] tal2 = { 2, 6, 5, 2, 35 }; // you are initializing int[]
string[] str = { "hej", "på", "dig" }; //you are initializing string[]
推荐阅读
- python-3.x - 如何在 python 中将列表转换为具有特定格式的字典?
- c# - 如何在 .Net Core 中启动后添加 dbContext?
- android - 如何以编程方式更改 android.support.design.widget.FloatingActionButton 颜色
- react-native - ScrollView 不允许滚动,除非子组件是 Button 或 Touchable
- javascript - 如何在我的 .cshtml 页面中调用 Vue 组件?
- reactjs - 无法正确反应关闭织物面板
- python-3.x - 在标记化时我遇到了这个错误
- angularjs - Angular:检测到变量更改时如何自动重新渲染?
- python - 在 Python 中将命名空间放入不同的 XML 标记中
- php - 获得产品可见性价值 - WooCommerce