上课有问题

发布于 2024-12-11 14:11:34 字数 203 浏览 4 评论 0原文

我知道 VB.NET 中很少使用类。我到处寻找,试图理解 C# 中的类是如何工作的,就好像我需要对我学到的每一课进行类比,我有逻辑和循环,但是当涉及到类时,我的大脑就冻结了。我尝试过书籍和在线教程。我一生都无法理解类是如何工作的以及它们如何在链接之间调用。对我来说,学习 C 语言的指针几乎同样困难。

有谁知道一个好的资源或网站,即使对于非天才技术人员来说,也能均匀地分解它?

I know classes aren't used much in VB.NET. I have looked everywhere trying to understand how classes work in C#, it's as if I needed an analogy for each lesson I have learned, I have logic and loops down, but when it comes to classes, my brain just freezes up. I have tried books and online tutorials. I for the life of me cannot understand how classes work and how they are called between linking. Its almost as hard for me to learn pointers in C.

Does anyone know a good resource or site that will break it down evenly even for the non-gifted tech?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云柯 2024-12-18 14:11:34

毫无疑问,互联网上有大量包含此信息的资源,但如果我可以指出C# 语言规范(具有进一步链接):

1.6 类和对象

< /a> 是 C# 中最基本的类型。类是一种结合了状态(字段)和
单个单元中的操作(方法和其他函数成员)。 A类
提供动态创建的定义
类的实例
也称为对象< /a>.类支持继承多态,
派生类< /em> 可以扩展和专门化基础

新类是使用类声明创建的。 A类
声明以指定属性的标头开始,
类的修饰符、类的名称、基类(如果
给定),以及该类实现的接口。标题是
接下来是类主体,其中包含成员列表
声明写在分隔符 { 和 } 之间。

以下是一个名为 Point 的简单类的声明:

public class Point
{
    public int x, y;
    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }
}

类的实例是使用 new 运算符创建的,它
为新实例分配内存,调用构造函数
初始化实例,并返回实例的引用。这
以下语句创建两个 Point 对象并存储对的引用
这些对象在两个变量中:

Point p1 = new Point(0, 0); 
Point p2 = new Point(10, 20); 

对象占用的内存自动
当对象不再使用时回收
。也没有必要
也不可能在 C# 中显式释放对象。

这些信息是底线,应该冷静地理解 - 重要外围(但基本)方面的链接在某种程度上提供了进一步的阅读。享受!

There are plenty of resources all over the internet with this information, no doubt, but if I may point out what is noted in the C# Language Specification (with further linkage):

1.6 Classes and objects

Classes are the most fundamental of C#’s types. A class is a data structure that combines state (fields) and
actions (methods and other function members) in a single unit. A class
provides a definition for dynamically created instances of the class,
also known as objects. Classes support inheritance and polymorphism,
mechanisms whereby derived classes can extend and specialize base
classes
.

New classes are created using class declarations. A class
declaration starts with a header that specifies the attributes and
modifiers of the class, the name of the class, the base class (if
given), and the interfaces implemented by the class. The header is
followed by the class body, which consists of a list of member
declarations written between the delimiters { and }.

The following is a declaration of a simple class named Point:

public class Point
{
    public int x, y;
    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }
}

Instances of classes are created using the new operator, which
allocates memory for a new instance, invokes a constructor to
initialize the instance, and returns a reference to the instance. The
following statements create two Point objects and store references to
those objects in two variables:

Point p1 = new Point(0, 0); 
Point p2 = new Point(10, 20); 

The memory occupied by an object is automatically
reclaimed when the object is no longer in use
. It is neither necessary
nor possible to explicitly deallocate objects in C#.

This information is the bottom line, and should be coldly understood - the links to important peripheral (but fundamental) aspects go some way to provide further reading. Enjoy!

娜些时光,永不杰束 2024-12-18 14:11:34

一个类:

public class Program
{
    public void Run()
    {
        Console.WriteLine("Hello world");
    }
}

运行它:

var program = new Program();
program.Run();

A class:

public class Program
{
    public void Run()
    {
        Console.WriteLine("Hello world");
    }
}

running it:

var program = new Program();
program.Run();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文