LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-14-2006, 09:48 AM   #1
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Rep: Reputation: 30
c# constructors and destructors???!!!??


hello all i have two main classes one form class and one class that is going to act as fake host on a network.

the first class just uses glade to control some buttons and a text box on a form, and the second class at the moment does very little. the problem i have is this:

when i start the program i want the first class to create an instance of the other class like this:

host a = new host();

this works fine however, i cant destroy the object once i have created it without closing the application and restarting it this is the code to my second class:

Code:
using System;


namespace learning_bridge {
	
	
	public class host {
		
	// define variables 
			public string name = "";
			public int connected;
		
			private const int MAX_TTL = 120;
			private int TTL = 0;
			private Random rndConnected = new Random();
			
			private enum port { ONE, TWO }
	// end variable definitions
	
		
		public host( string newName ) {
			name = newName;
			connected = rndConnected.Next( 1, 6 );
		}
		
		
		public void Dispose() {
			
		}
	
	
	}
the first class creates this class file after the public class function using host a = new host(); it is important to leave this code here. i just need to know how to dispose of class files,

thanks trscookie.
 
Old 06-15-2006, 03:29 AM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Not being a C# programmer I could be horribly wrong but I believe that all you need to do to dispose of an object is to remove all references to that object, hence you would do something like a = null;
 
Old 06-15-2006, 04:21 AM   #3
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Original Poster
Rep: Reputation: 30
yea your right cheers i need to declare it like:

hosts a = null;

then when i want to use it:

a = null;
a = hosts( "a", time );

this inits the class in the program then loads it when i call it using the second command. cheers trscookie.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
JAVA: Reference Variables (Pointers) and Constructors wwnexc Programming 14 03-10-2006 03:31 AM
C++ - throwing exceptions in derived class constructors? MadCactus Programming 4 08-09-2004 06:29 AM
virtual destructors in C++ Komakino Programming 5 07-06-2004 03:32 PM
what are c++ static constructors/destructors? cybercop12us Programming 2 01-24-2003 03:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration