Visual Studio 2015 突然不想在类中创建新变量 [英] Visual Studio 2015 suddenly don't want to create new variables in classes

查看:30
本文介绍了Visual Studio 2015 突然不想在类中创建新变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我几乎整天都在为这个问题苦苦挣扎,我在互联网上没有找到任何答案.我知道这个修复只是为了改变一件小事,但我不知道是哪一件.卸载(使用 TotalUninstaller)visual studio(community 2015)没有解决我的问题.介绍的话就到这里了...

I'm struggling with the issue almost whole day, I didn't find any answer in the internet. I know this fix is just to shift one small thing, however I have not idea which one. Uninstall (using TotalUninstaller) of visual studio (community 2015) didn't fix mine problem. That's it for the word of introduction ...

我无法在类中定义任何对象/变量.不管是新项目还是现有项目.

I can't define any object/variable in classes. Does not matter is it in new project or existing.

现有项目中类的示例片段:

Example Snippet of a class in existing project:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGDS
{
    public class Similarity
    {
        public string index;
        public double distance;
        public double similarityRate;
        public Similarity(string index, double distance)
        {
            this.index = index;
            this.distance = distance;
        }
        // NEW PART WHICH HAS BEEN ADDED
        int b;
        b = 100;
        // END
    }
}

当我尝试构建时收到以下错误

When I try to build I receive following errors

Error   CS1519  Invalid token '=' in class, struct, or interface member declaration AGDS
Error   CS0103  The name 'b' does not exist in the current context. AGDS

此外,在我能够定义的 Program.cs 类中的任何项目中.我有一种奇怪的感觉,安装本地 SQL 服务器可能会破坏某些东西......有没有人知道什么是错误的以及如何解决它?

Moreover in any project in Program.cs class I'm able to define. I have strange felling that installation of local SQL server could broke something ... Has anyone got idea what can be wrong and how to fix it?

推荐答案

是否可以声明变量然后在函数之外为这些变量赋值?

Is it possible to declare variables then assign values to those variables outside of a function?

尝试这样做:

public class Similarity
{
    public string index;
    public double distance;
    public double similarityRate;
    public Similarity(string index, double distance)
    {
        this.index = index;
        this.distance = distance;
    }

    int b = 100;  //new code
}

这篇关于Visual Studio 2015 突然不想在类中创建新变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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