简体   繁体   English

什么是基于实例的成员

[英]What is instance based member

in here I want to know what is instance based member? 在这里我想知道什么是基于实例的成员? what I think is instance based member == instance variable. 我认为是基于实例的成员==实例变量。 Am I correct? 我对么? If I'm correct, then how can I know which is variable or instance variable? 如果我是正确的,那我怎么知道哪个是变量或实例变量? The variable which under constructor that will become to instance variable, right? 在构造函数下将变为实例变量的变量,对吗? Or did I misunderstand? 还是我误会了?

An instance member is essentially anything within a class that is not marked as static . 实例成员实际上是一个未标记为static的类中的任何内容。 That is, that it can only be used after an instance of the class has been made (with the new keyword). 也就是说,它只能在创建类的实例后使用(使用new关键字)。 This is because instance members belong to the object , whereas static members belong to the class . 这是因为实例成员属于该对象 ,而静态成员属于该类

Members include fields, properties, methods etc. 成员包括领域,属性,方法等。

For example: 例如:

class Example
{
  public static int Value1 { get; set; } // Static property

  public int Value2 { get; set; } // Instance property

  public static string Hello() // Static method
  {
    return "Hello";
  }

  public string World() // Instance method
  {
    return " World";
  }
}

Console.WriteLine(Example.Hello() + new Example().World()); // "Hello World"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM