【发布时间】:2021-01-27 17:44:41
【问题描述】:
我是 C# 学习的新手,这是我关于堆栈溢出的第一个问题。当我尝试初始化变量时,我收到错误代码 CS0103(名称“exampleInt”在当前上下文中不存在)。但是,如果我在声明它的同一行(上一行)初始化它,则不会出现错误。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassLibrary1
{
public class Class1
{
// No error shows up here for
// private int exampleIn=77;
private int exampleInt;
// error on following line
exampleInt=77;
}
}
【问题讨论】:
-
将最后一行代码放入函数中。
标签: c# visual-studio-2015 class-library