首页 > 解决方案 > 此 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 只能使用数组初始化表达式来分配给数组类型

标签: c#

解决方案


正确的表达方式是这样的

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[]

推荐阅读