Click here to Skip to main content
15,565,474 members
Home / Discussions / C#
   

C#

 
Questionhow do i enable directx? Pin
godzooky23-Jan-04 6:20
godzooky23-Jan-04 6:20 
AnswerRe: how do i enable directx? Pin
sammyh23-Jan-04 6:33
sammyh23-Jan-04 6:33 
AnswerRe: how do i enable directx? Pin
Heath Stewart23-Jan-04 6:35
protectorHeath Stewart23-Jan-04 6:35 
GeneralRe: how do i enable directx? Pin
godzooky23-Jan-04 7:13
godzooky23-Jan-04 7:13 
GeneralRe: how do i enable directx? Pin
Heath Stewart23-Jan-04 7:34
protectorHeath Stewart23-Jan-04 7:34 
GeneralRe: how do i enable directx? Pin
AllanC123-Jan-04 18:34
AllanC123-Jan-04 18:34 
GeneralNeed help from someone with C++ background Pin
J. Eric Vaughan23-Jan-04 5:39
J. Eric Vaughan23-Jan-04 5:39 
GeneralRe: Need help from someone with C++ background Pin
Heath Stewart23-Jan-04 6:17
protectorHeath Stewart23-Jan-04 6:17 
public void Foo()
{
  MyClass o = new MyClass();
  Bar(o);
}
public void Bar(object data)
{
  MyClass o = (MyClass)data;
}
In .NET, everything deriving from Object (except for ValueType and its derivatives like the intrinsics, enums, and structs) are reference types already (well, the instances of the classes deriving from Object) and everything derives from Object. So, for anything declared as a class, it's instance is a reference type.

As far as sending objects to another context, .NET Remoting is the de facto technology in .NET to do this. In the base class library, you can choose from the BinaryFormatter or the SoapFormatter (binary would obviously be faster but not easily interoperable with other technologies like J2EE). Serialization is required when crossing different contexts (even within the same AppDomain) and Remoting is recommend (required in some cases) when crossing AppDomains (even within the same process, which it's recommended you use a TcpChannel for communication). See Accessing Objects in Other Application Domains[^] on MSDN for more information.

For a good intro and intermediate book on .NET Remoting, see "Microsoft .NET Remoting"[^] by McLean, Naftel, and Williams.

As far as dealing with base classes, this is easily handled by an object-oriented framework like .NET and Java. For example, you could declare a parameter as even an Object, or the base class for your objects. The Common Type System (CTS) will ensure that when you're compiling any direct calls to that method use a parameter that is indeed a derivative class of the parameter Type. If you use abstract and virtual methods in your base class and override those in your derivative classes, those methods will be called instead of their base class's methods (you can use the base keyword to call the base class's methods inside the overridden methods). This is polymorphism. See the Common Type System[^] for some more information.

For example, the Object class has a virtual ToString method that, by default, returns the object's Type. If a class overrides this, it can return something else. An Enum returns the enum member name (or a comma-delimited list of names for enums that are attributed with the FlagsAttribute). Many other classes override this method as well.

Also, the Object.GetType method is not virtual and will return the actual Type of the object, regardless of whether the variable is declared as an object or another base class:
object o = new Button();
Console.WriteLine(o.GetType());
Would print:
System.Windows.Forms.Button
So, you can use the GetType to see if you're dealing with an Elephant or a Dog (BTW, the hungarian notation is not recommended for use in .NET languages - just thing of what the base class library uses for examples of how to name your classes, etc., or see the Naming Guidelines[^]).

The C# language makes this easier with several keywords you can use, such as is and as:
public void Feed(Animal a)
{
  if (a is Elephant) Buy(Food.Peanuts);
  if (a is Dog) Buy(Food.Peanuts);
}
Of course, the above example is better suited for polymorphism by using the abstract keyword and overriding in the derivate classes to feed the animal what's necessary, but it's just an example.

 

-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
GeneralRe: Need help from someone with C++ background Pin
J. Eric Vaughan23-Jan-04 7:33
J. Eric Vaughan23-Jan-04 7:33 
GeneralRe: Need help from someone with C++ background Pin
Heath Stewart23-Jan-04 7:36
protectorHeath Stewart23-Jan-04 7:36 
GeneralRe: Need help from someone with C++ background Pin
J. Eric Vaughan23-Jan-04 9:42
J. Eric Vaughan23-Jan-04 9:42 
Questionhow to load referenced assemblies Pin
occcy23-Jan-04 5:23
occcy23-Jan-04 5:23 
AnswerRe: how to load referenced assemblies Pin
Heath Stewart23-Jan-04 5:53
protectorHeath Stewart23-Jan-04 5:53 
GeneralGAC / Reference / VStudio Pin
dabossuk23-Jan-04 3:25
dabossuk23-Jan-04 3:25 
GeneralRe: GAC / Reference / VStudio Pin
Heath Stewart23-Jan-04 5:44
protectorHeath Stewart23-Jan-04 5:44 
GeneralMultiple InternetExplorer objects' DownloadComplete event Pin
profoundwhispers23-Jan-04 1:07
profoundwhispers23-Jan-04 1:07 
GeneralRe: Multiple InternetExplorer objects' DownloadComplete event Pin
Mazdak23-Jan-04 3:20
Mazdak23-Jan-04 3:20 
GeneralRe: Multiple InternetExplorer objects' DownloadComplete event Pin
profoundwhispers23-Jan-04 5:17
profoundwhispers23-Jan-04 5:17 
GeneralRe: Multiple InternetExplorer objects' DownloadComplete event Pin
Mazdak23-Jan-04 5:34
Mazdak23-Jan-04 5:34 
GeneralRe: Multiple InternetExplorer objects' DownloadComplete event Pin
Heath Stewart23-Jan-04 5:42
protectorHeath Stewart23-Jan-04 5:42 
GeneralRe: Multiple InternetExplorer objects' DownloadComplete event Pin
profoundwhispers23-Jan-04 5:53
profoundwhispers23-Jan-04 5:53 
GeneralRe: Multiple InternetExplorer objects' DownloadComplete event Pin
Heath Stewart23-Jan-04 5:58
protectorHeath Stewart23-Jan-04 5:58 
GeneralHelp with Collections Pin
crushinghellhammer22-Jan-04 19:19
crushinghellhammer22-Jan-04 19:19 
GeneralRe: Help with Collections Pin
Heath Stewart22-Jan-04 19:49
protectorHeath Stewart22-Jan-04 19:49 
GeneralRe: Help with Collections Pin
crushinghellhammer22-Jan-04 20:32
crushinghellhammer22-Jan-04 20:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.