Re: Class Placement - stupid question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



> 1. Do I have to have the tank.cs class file, or can I just place it in the
> application namespace?

It doesn't matter in which file (*.cs) your class is. You can put your
class anywhere you like, as far as you specify the proper namespace for it.
(Class are put into different files usually for team works or for some other
purposes. It is not a "must" to do this in your applications.)

> 2. Shouldn't I be able to instantiate classes anywhere in my event code?
> If
> not, how can I?

Your classes are not instantiate as far as you have not used the "new +
className". This means that you can instantiate your class in your event
code. Sth like this will not instantiate the class unless you invoke the
Click method:

//--------------------------------------------------------

MyClass cls; // < - This is where you set the type of your identifier (or
object)

public void Click()
{
cls = new MyClass(); // <- This is where the class is instantiated.
cls.DoSth(); //< This is where you can use the instance members of the
class
}

//-------------------------------------------------------------

Also, you should make sure that your classes are instantiated before you can
use their instance (non-static) members. If in another method in your code
you try to use the class while it has not been instantiated, you will face
errors. As a result, you should try to whether instantiate all you classes
in the application's Main() entry (which is not so common) or instantiate
them in your methods wherever you like and "then" use its members,



.



Relevant Pages

  • Re: ProgID in .NET?
    ... The ProgID has the form Project.ClassName.Version. ... version it is possible to instantiate COM objects from different versions ... When a class from a .NET assembly is instantiated its namespace and class ... The nice part about COM is that you can choose as a developer if you want to use a specific version of a COM object or not without the vendor of the DLL facing the problem we ran now into: If we don't change the namespace you can't use different versions in the same process. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Can we create an_object = object() and add attribute like for a class?
    ... Is there any reason that under Python you cannot instantiate the object ... which may make little sense for a namespace). ...
    (comp.lang.python)
  • Re: Can we create an_object = object() and add attribute like for a class?
    ... Is there any reason that under Python you cannot instantiate the object ... I was under the impresssion that instances of type object did have a __dict__ but was hidden for some reason. ... which may make little sense for a namespace). ... any natural way of declaring a namespace SHOULD allow ...
    (comp.lang.python)
  • Gettype() returning a null
    ... html = "Hello World" ... public string emit{ ... In my webpage, I am trying to instantiate myObject dynamically, like ... My Type t will return null unless I include the CMS namespace in the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: HOWTO Overcome missing namespace declaration in root node
    ... the tag of the root element, including all namespace definitions ... the line of code where you instantiate the XmlSerializer ...
    (microsoft.public.dotnet.xml)