C# - 如何使程序没有IDE / Visual Studio的? [英] C# - How to make programs without IDE/Visual Studio?

查看:120
本文介绍了C# - 如何使程序没有IDE / Visual Studio的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在在记事本+ + C#控制台应用程序和MonoDevelop的,只有一个cs文件,而不是一个解决方案。我编译从CMD的代码。

I am making C# console applications in Notepad++ and MonoDevelop with only a .cs file instead of a solution. I compile the code from CMD.

我想在我的简单的黑客攻击的程序,只是简单地显示了很多0和1的增加两班。每次我试图让一个对象的引用,我得到的编译错误说我需要非静态字段的参考。制作的方法静态的作品,但我不认为每个方法应该是静态的。

I want to add two classes in my simple "Hacked" program that just simply displays a lot of 0's and 1's. EVERY time I try to make an object reference, I get an error in the compiler saying that I need to make a reference for non-static fields. Making methods static works, but I don't think that every method should be static.

所以我的问题是,如何让我的对象引用没有一个IDE?

So my question is, how do I make object references without an IDE?

编辑:我已经通过该变量静态找到了解决办法。我知道,当一个方法是静态的,它可以从任何类没有引用访问。我只是测试类的引用,以了解更多一点关于C#。但我使这个类引用变量静态的东西,是不是在被引用类的静态工作正常。谢谢大家帮助我,虽然作为您的建议和解释确实帮助我。

I have found the solution by making the variable static. And I knew that when a method was static, it could be accessed from any class without a reference. I was just testing a class reference to learn a little more about C#. But I make the class reference variable static and anything that isn't static in the referenced class works fine. Thank you all for helping me out though as your suggestions and explanations did help me.

推荐答案

很高兴看到有人开始这么简单。对象引用是一样的,不管你在VisualStudio的工作,或在一个简单的文本编辑器。

Nice to see someone starting so simple. Object references are the same no matter if you are working in VisualStudio, or in a simple text editor.

这实际上是在你的代码的,而不是说你不使用IDE的事实。

This is actually an error in your code and not the fact that you are not using an IDE.

我假设你没有去成面向对象的编程太多了,而这些都是简单的单级方案,以帮助您开始。

I'm assuming you have not gone into object oriented programming too much, and that these are simple, single class programs to help you get started.

在这种情况下,所有其他方法,领域等,都是以某种方式从你的公共静态的主要(字串[] args)方法来访问。静态方法是所有类访问,并且不需要对象实例。没有一个实例访问方法和字段必须是静态的。

In this case, all other methods, fields, etc, are accessed in some way from your public static Main(string[] args) method. Static methods are accessible from all classes, and do not require an object instance. Methods and fields accessed without an instance must be static.

因此​​,在这种情况下,是的,每一个方法的确实必须是静态的。

So, in this case, yes, every method does need to be static.

看看这个问题,什么静态方法?

例如,假设您创建了一个名为类数学,和创建一个战俘(INT X,INT功率)(功率)的方法(这是.NET Framework的一部分)。你会作出这项功能静态,因为你希望所有的类能够在不创建数学的一个实例来访问它一流

For example, say you create a class called Math, and create a Pow(int x, int power) (power) method (This is part of the .NET framework). You would make this function static because you want ALL classes to be able to access it without creating an instance of the Math class.

int square = Math.Pow(2, 2); //Static method, no instance needed

现在说,你犯了一个叫做类图书,这个类有方法,如 GetPagesLeft()。在这种情况下,它是专用于一个书的每一个实例,并且不应静态的,因为它适用于每个实例

Now say, you make a class called Book, this class has methods such as GetPagesLeft(). In this case, it is specific to each instance of a "book", and should not be static, because it applies to each instance.

Book book = new Book(); //Create instance
int pagesLeft = book.GetPagesLeft(); //Instance method



不要害怕使用静态方法,它们是有原因的。

Don't be afraid of using static methods, they are there for a reason.

请注意,我不是一个专业的开发人员,所以一些我以前可能不完全正确的术语,但我希望得到跨越点。

Note, I'm not a professional developer, so some of the terminology I used may not be exactly correct, but I hope it gets the point across.

这篇关于C# - 如何使程序没有IDE / Visual Studio的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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