|
reading about interfaces, i understand that its a contract and you have to implement all methods/properties/events...etc once you inherit an interface, what i dont understand is why this example casts back to an interface to execute the method
interface IVehicle
{
void Start();
}
class Car : IVehicle
{
public Car() { }
public void Start() { Console.WriteLine("starting..."); }
}
--test class--
void Main()
{
Car myCar = new Car();
IVehicle vehicle = (IVehicle)myCar;
vehicle.Start();
}
anyone can give me some real world examples as to when/why you would cast back to an interface to access methods/properties?
thanks
|
|
|
|
|
What about just expanding your sample here.....
<code>interface IVehicle
{
void Start();
}
class Car : IVehicle
{
public Car() { }
public void Start() { Console.WriteLine("starting Car..."); }
}
class Truck : IVehicle
{
public Truck() { }
public void Start() { Console.WriteLine("starting Truck..."); }
}
--test class--
void StartVehicle(IVehicle vehicle)
{
vehicle.Start();
}
void Main()
{
Car myCar = new Car();
IVehicle vehicle = (IVehicle)myCar;
Truck myTruck = new Truck();
IVehicle vehicle2 = (IVehicle)myTruck;
StartVehicle(vehicle);
StartVehicle(vehicle2);
}</code>
This way a function that can take any type of vehicle can be used on either a Car or a Truck.
Steve Maier, MCSD MCAD
|
|
|
|
|
ahh that makes sense.
Thanks Steve
|
|
|
|
|
I'm using Visual C# Express. My problem is I don't know how to switch between Debug and Release builds. I've checked the help and they talk about opening the Configuration Manager or using the Solution Configuration Pages or Menubar, but I can't get to any of these. The solution configuration dropdown (on the toolbar) is disabled. There is no entry for "Configuration Manager" in the Build menu, which is where help says it should be located. In the Solution Property Pages I only have three pages: Startup Project, Project Dependencies, and Debug Source Files.
My project (according to it's property pages output directory) seems to be stuck in Release mode, and I've no idea how to change it. Any help on this problem would be much appreciated.
Thanks.
- Aaron
|
|
|
|
|
Given an instantiated class, which is made up of strings, lists and values. Is there a way to easily determine how much real memory that object is using?
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Please im working on smart devices application on C# and i want to know how i can connect a database with it as the windows application.
im trying to use Using System.data.oledb
or Using System.data.sql
But no response.
so please please help me.
thanx and wish u solve me this problem
tedy
|
|
|
|
|
What part of it are you having problems with, The connection to the database? What database are you trying to connect to? Are you getting error messages?
|
|
|
|
|
dude i dont know HOW to connect
im in the beging
but i will answer your qustions
the part :all
connection type : i think in oledb
and also i will explan what im trying to do
-> im trying to make an system that take the value from txtbox and send it by get or post method to a server that contain the data base, search for it and send the full information of the searched word as age,gender..etc back to the device ,and the device take these arguments and reorder them in datagrid. this one of the ideas
the second to make a direct access to this data base and search directly i.e make the connection connected with the ftp folder on the server to db file.
thanx but im still begineer
solve me this problem PLZZZZZZZZZZZ
and if u have any other ideas plz tell me thanx again
tedy
|
|
|
|
|
Well the first thing you need to do is send the connection string to the database server telling it who you are, a password...etc. Lookup tutorials on SQL or OLDB connections. There are tons of good information on how to do what you are trying.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
(Type your message here)
--------------------------------
From: subramaniam chandrasekaran
Hi
I am using XML serialization to serialize an xml. I want to apply business rules to this object,rules are defined in the database. I am trying to get the value in the serialized object and apply the rule. I am trying to use reflection to get the value in the serialized object. Is there a way i can retrieve all the values in the serialized object? My xml has complex nodes inside the root element. Any sort of help is really appreciated.
subbu
|
|
|
|
|
I have one C# application (APP1) starting a second C# application (APP2).
If APP1 starts APP2 something like the following, everything works okay:
\\.\C$\APP2.EXE
If APP1 starts APP2 something like the following, I get a Security.Permission problem:
\\CAROL-LOVE\C$\APP2.EXE
The following should give you an idea of the code I'm trying to run. What I'm
trying to do is so simple that it's infuriating that this much time is being taken to get it to work!!!!!!
static void Main(string[] args)
{
Application.Run(new CFormMAINAPP2(args));
}
public CFormMAINAPP2(string[] args)
{
string[] argsXXX = args; // Security.Permission exception here...
}
|
|
|
|
|
|
How can I add my own methods to Array Class of NET Framework Class Library ?
For example, I want to use it like
Array.GetXXX();
Thank you in advance.
Nuray
|
|
|
|
|
You can't. You have to wait till C# 3.0 is released to do that. C# 3.0 has a new language feature called "Extension methods" that allow you to do what you want.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Dear Senthil,
How about using Class Array as a base clase?
Nuray
|
|
|
|
|
I don't know if the Array class is sealed, if it is, then you won't be able to derive from it. I still don't think it's a useful idea for your requirement, because it doesn't allow you to add methods to Array, it only allows your class to use extend the Array class.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Do you think it is good idea to use ArrayList that can hold some arrays and instances of my classes?
Nuray
|
|
|
|
|
|
Instead of using a class which inherits from a base vector class, I want to use System Array Class or ArrayList class so that I can combine my own methods with the methods already built in NET Framework Class Library.
Is that clear ?
Nuray
|
|
|
|
|
Pretty much all of Array's functionality is static anyway, (eg, Sort, IndexOf, BinarySearch) so why not just write a wrapper class, storing a private member of type Array and expose the functionality you require?
|
|
|
|
|
This is what I was thinking at the beginning then I thought there could be another way, like inheritance.
I usually use my own class for array operations as an ex-C++ user but why not to use built in classes and methods available in NET Framework Class Library. Any way, What I have learned from all comments until now, It is reasonable to follow your suggestion. Thank you .
Nuray
|
|
|
|
|
You can create your own array class which inherits from the System.Array class.
class MyArray : System.Array
{
public Object GetXXX(int myKey)
{
foreach (Object obj in this)
{
}
return null;
}
}
[Modified]
Bummer. The above solution doesn't work. You're not allowed to derive from Array. However, the 2 solutions below will do the job.
[/Modified]
Or you can create your own "collection" class which inherits from the CollectionBase class.
Or you can create your own "collection" class which wraps an Array object. You should implement the ICollection and IEnumerable interfaces in this case.
-- modified at 14:08 Monday 21st November, 2005
|
|
|
|
|
Why did I get such a message
"UsingArray.ArrayClass' cannot inherit from special class 'System.Array'?"
I use .Net 2003. Thank you in advance.
Nuray
|
|
|
|
|
Well shoot. It's not sealed, but apparently you're not allowed to derive from it. I found the following text on MSDN describing this.
The Array class is the base class for language implementations that support arrays. However, only the system and compilers can derive explicitly from the Array class. Users should use the array constructs provided by the language.
I'm afraid you are going to have to wrap it.
|
|
|
|
|
public class ArrayClass : System.Collections.ArrayList
{
//
};
This works as suggested by Robert Rohde
|
|
|
|