|
- Interfaces lets you make multiple inherance.
The best examples are IList,ICollection,IEnumerate from the System.Collections namespace.
- Interfaces makes you focus on design before starting to actually do any coding. Ok, an example.
Consider you need to develop a product that manages customers, products and orders (classic example). Note that when starting to design the product, you do not know "implementation" details like how the data will be stored, etc...
The problem is sufficiently simple we don't have to go through UML and stuff but we can use interfaces to defines the relationships between the objects
public interface ICustomer
{
string Name {get;}
}
public interface IProduct
{
string Name {get;}
}
public interface IOrder
{
ICustomer Customer {get;}
IProduct Product {get;}
int Quantity {get;}
}
Here you can see the relationships between ICustomer, IProduct and IOrder. It is important to note that you have not written any "line of code" yet. You have just defined the objects. After that, you can implement the interface for database data, XMl file etc...
:=)
Jonathan de Halleux.
www.dotnetwiki.org
|
|
|
|
|
there's a couple reasons I use an interface. one of the biggest is so that I can write a function that can handle a generic reference of a class
here's an example I used it for
I created an ILookupTable interface that had methods like
Add(), Edit(), Delete(), SortUp(), SortDown() etc.
and then created several classes that implmented this interface
StateLookupTable,
TelephoneTypeLookupTable,
AddressTypeLookupTable
From there I could create one GUI that handled maintaining my lookup tables. When I needed to pass a class as a parameter, I would have a call like: public void MyCall(ILookupTable table)
and I knew I could call all of the properties and methods in that interface without actually having to know which particular class I was working with.
|
|
|
|
|
I have a two formed application in C#. I need to know how to get an integer from the initial form, to the second one.
|
|
|
|
|
What is the desired behavior of the two forms, i.e., what order will they be displayed, will the both be open at the same time, should one disappear...
Anyway, you might try passing the value from the first form to the constructor of the new form.
|
|
|
|
|
|
Something like this:
namespace FormConstructorParam
{
public class OverloadedConstructor : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
private int _value;
public OverloadedConstructor()
{
InitializeComponent();
}
public OverloadedConstructor(int someValue)
{
InitializeComponent();
_value = someValue;
}
}
}
then, when you create the instance of the form, you do this:
OverloadedConstructor oneForm = new OverloadedConstructor(1);
or this:
OverloadedConstructor anotherForm = new OverloadedConstructor();
|
|
|
|
|
The value could also be stored in a field or a property of either one or both of the forms...
|
|
|
|
|
Follow steps below:
1- Define a public or internal property inside your initial form(source class), which holds the integer value to send.
2- Define an overloaded constructor for the second form(destination class), which accepts an instance of the first form(i.e. Form1) as input parameter.
3- When instanciating the destination class(Form2), pass this keyword as input parameter to its constructor .
4- In destination class's constructor you have access the sourcr class's property, through this.PropertyName .
I hope this helps.
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|
|
I'm sorry, i'm fairly new to this, could you give me an example?
|
|
|
|
|
I want to write a console application, Which will convert arabic numbers to roman.
But the problem is in roman 5000,10000 etc will be represented as V and a "-" symbol upon V..but i dont how to get these characters please let me know how to write a string a "-" upon them.
Please note that this is for console application
Its very urgent
|
|
|
|
|
Sounds like a class assignment for a computer science class...
GetOn&GetGoing wrote:
5000,10000 etc will be represented as V and a "-" symbol upon V
What do you mean, the fact that the roman numeral for five is a V with exaggerated serifs?
|
|
|
|
|
Ya i got it...
But how you will represnt 5000 you cant represent with "MMMMM", you should represnt as V and a "-" on that, i dont know how to print this kind of special characters in console application.
|
|
|
|
|
Ok, so a horizontal line over the roman numeral V is supposed to represent the fact that the number is multiplied by 1000. I think that that usage isn't really in vogue any more, but if it is necessary, how about writing an underscore ("_") on the line above the value?
|
|
|
|
|
Ya that will be fine with me...
But how to do that for a consle application
|
|
|
|
|
Ok, you know that you generate output in a console application with Console.Write() and Console.WriteLine() , right?
So, figure out which position of your roman number is the 1000's, then write an underscore on the line before you write the roman numerals:
Console.WriteLine("_");
Console.WriteLine("VCXIX");
|
|
|
|
|
Can any body send me the interview questions..I dont want direct questions
I wan the questions which are very tricky and concptual....
|
|
|
|
|
Try Programming Interviews Exposed (Mongan & SUojanen) published by Wiley.
|
|
|
|
|
I think you missed a forum hear
But if this is somehow C# related please be more specific!
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
CWIZO wrote:
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
LOL
|
|
|
|
|
Thanx, made that ups myself
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
I am using a numericUpDown control which represents a minutes (for time) value. I want it to display 00, 01, 02, etc... for numbers less than 10. Is there a simple way to do this with a property (I reviewed the documentation, but didn't see anything immediately)?
I know I could do it if I inherit the control, but I was hoping for a simple property or somethign to accomplish it. Something that I missed in the documentation.
Can it be done without inheriting it?
There are only 10 types of people in this world....those that understand binary, and those that do not.
|
|
|
|
|
The property you are looking for is not available.
|
|
|
|
|
No property like this is available, but if you extend NumericUpDown you can simply override UpdateEditText . If Hexidecimal is set, be sure to call the base.UpdateEditText unless you want to handle this yourself. Also, when formatting the number, don't forget to take the ThousandsSeparate into account.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank Heath...that's kind of what I thought. I figured I'd have to inherit/extend it to make it work. I just wanted to make sure there wasn't a property for it that I missed before I went through all the trouble.
There are only 10 types of people in this world....those that understand binary, and those that do not.
|
|
|
|
|
I take it that you looked at the class documentation for the NumericUpDown class, right? Deriving from your sig, "there are 10 types of people in this world...those that read the documentation and those that do not." (Unfortunately, most of the posters here fall in the latter category.)
Typically, you can learn everything you need to know from the docs (add that to experience and reading articles on MSDN, CodeProject, et. al.). If some member overrides a base member of defined new and you find the documentation a little lacking on details, use ildasm.exe - the IL disassembler that comes with the .NET Framework SDK - to view the IL for the implementation in that assembly, or use a good decompiler like .NET Reflector[^] (though its decompiler rarely incorrect / incomplete). You can learn a heck of a lot that way - perhaps even pick up a few pointers from the developers at Microsoft who wrote the base class libraries.
Microsoft MVP, Visual C#
My Articles
|
|
|
|