"是一个领域,像一个类型所用,;错误 [英] "is a field and used like a type" error

查看:103
本文介绍了"是一个领域,像一个类型所用,;错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在C#类库项目中使用的StringBuilder 。我已经添加了使用语句和所有。 。我没有得到IntelliSense和我得到一个编译错误

I am trying to use StringBuilder in a C# Class Library project. I have added the using statement and all. I am not getting intellisense and I am getting a compile error.

例如:

StringBuilder sb= new StringBuilder();
sb.Append("");



我看到的变量 SB ,那

SB 是一个领域,像一个类型使用。

sb is a field and used like a type.

任何帮助表示赞赏。

推荐答案

不看你的完整代码,我只能猜测,你是在类直接编写代码,以下行应该是一个方法

Without looking at your complete code I can only guess that you are writing your code directly in the class, Following line should be inside a method

sb.Append("");

有关的类应该是这样的:

For the class it should be like:

using System.Text; //make sure this is included. 
public class MyClass
{
  StringBuilder sb = new StringBuilder();

  public MyClass() //Constructor
  {
   sb.Append(""); //this statement should be inside a method
  }
}

目前它会是这样:

这篇关于"是一个领域,像一个类型所用,;错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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