We have several ways to create instance, how they do respectively? i want to know the details.
Is there somewhere having material to take a look?
Welcome to any comments.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sam HobbsPosted Jun 29, 2011, 2:12 PM
VulpesPosted Jun 29, 2011, 1:47 PM
Sam HobbsPosted Jun 29, 2011, 11:26 AM
Yes, "new" is static in the sense that the object to be created is determined at compile time in the same manner that for static linking the function to be called is determined at compile time. Also for the purpose of avoiding confusion, static linking is not possible using managed code.
The confusion can occur since "new" is used for classes but not static classes and static classes are not differentiated by compile time and execution time.
VulpesPosted Jun 29, 2011, 4:32 AM
Sam HobbsPosted Jun 28, 2011, 6:20 PM
Note that "new" is a part of the C# language but not .Net. The Activator Class is part of .Net and therefore can be used by any language that uses .Net. The "new" operator can only create objects for the one application that it is used in; it cannot be used to create objects in other computers or even not in other applications in the same computer. The Activator Class however can do all that; it looks very powerful. So you can use the Activator Class to do something in another computer, and do it as easily as if it was the same application.
It might be misleading to say that "new" is used to instantiate an object statically. The word static is used for C# classes and for static linking so it's use might be confusing here. I am sure that what is meant here is that "new" is used to create a specific object whereas the Activator Class can be used to create an object that can be specified in a variable and therefore can be determined during execution (dynamically). As best as I can see, dynamic creation is not the primary purpose of the Activator Class.
So is this the beginning of another creationism debate?
VulpesPosted Jun 28, 2011, 12:07 PM
When you call 'new' in the server it will still create an instance of the class in question. However, when you call AppDomain.CreateInstance from the client, then that does create a proxy which marshals method calls back to the real object on the server.
stevenPosted Jun 28, 2011, 7:56 AM
VulpesPosted Jun 28, 2011, 4:01 AM