When you instantiate a class or object, you're creating a new instance of it, or allocating memory to "hold" one. Initializing that object would be the instructions that are performed during instantiation.
I jab my finger at your code and say "this instance has an invalid property. Maybe that's why the loop fails. You gotta validate parameters during instantiation." (i.e. constructor arguments).
Declaration: The code set in bold are all variable declarations that associate a variable name with an object type.
Instantiation: The new keyword is a Java operator that creates the object.
Initialization: The new operator is followed by a call to a constructor, which initializes the new object."
其他人已经解释了其中的区别,所以我就不详细说了。但是在有些情况下,实例化不能正确地初始化对象。当你实例化一个对象时,你也会用一些数据来初始化它。类/类型具有初始化逻辑,而实例化逻辑通常由 new关键字执行(基本上是内存分配、引用复制等)。但是实例化不一定导致对象的有效状态,也就是我们可以说对象是 未初始化的时候。这里有一个实际的例子,一个对象可以被实例化,但是不能被初始化(抱歉,例如在 C # 中)。
class P { string name = "Ralf"; }
WriteLine(new P().name); // "Ralf";
WriteLine((FormatterServices.GetUninitializedObject(typeof(P)) as P).name); // null