473,396 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

interface design question

Hi-

I designed a control and although I'm the only one that will be using it, I
thought it a good idea to create an interface for it.

First question is how do you add fields to an interface?
I tried:
private interface ITest
{
string Name;
}

and I get a compile error on that.

Are you not supposed to add Fields to an interface?

Thanks for any help,
Steve
Nov 15 '05 #1
3 934
> Are you not supposed to add Fields to an interface?

No, because an interface defines a contract. You do not have an "instance of
an interface" like you have instances of classes. You *are* however able to
define properties which then must be implemented in a class:

interface ITest {
string Name { get; set; }
}

public class MyTest : ITest {
private string name;
public string Name {
get { return this.name; }
set { this.name = value; }
}
}

--
Peter Theill
http://theill.com/
Nov 15 '05 #2
perfect! That is actually what I wanted, I wanted to enforce the
properties, not the members themselves.
Thanks for the sample, I'm good to go now!
"Peter Theill" <reply@newsgroups> wrote in message
news:eC**************@TK2MSFTNGP11.phx.gbl...
Are you not supposed to add Fields to an interface?
No, because an interface defines a contract. You do not have an "instance

of an interface" like you have instances of classes. You *are* however able to define properties which then must be implemented in a class:

interface ITest {
string Name { get; set; }
}

public class MyTest : ITest {
private string name;
public string Name {
get { return this.name; }
set { this.name = value; }
}
}

--
Peter Theill
http://theill.com/

Nov 15 '05 #3
SP
Hi

Interface can only events, properties and methods. Fields or private member variables are not allowed in a interface
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Eric Veltman | last post by:
Hello everyone, I've posted this question before, but got no answer, so I'll try to reformulate the question, maybe it helps :-) By the way, this is not intended as the start of an ASP.NET...
9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
8
by: Ash | last post by:
Hello all, I am hoping this is the appropriate newsgroup for a C++ interface design question. I am trying to design an interface for a subscriber to register/deregister handlers for various...
3
by: Davide M3xican Coppola | last post by:
Hi, I would realize an interface (interface) for a pair of concrete classes (concrete & concrete2), but I have a problem because I have to access to a third class (element) and if I try to declare...
3
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability....
4
by: jm | last post by:
Consider: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconwhenshouldiimplementinterfacesinmycomponent.asp // Code for the IAccount interface module. public...
20
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my Interface that my DAL-objects implementing the...
6
by: Zach | last post by:
Hi everyone, I'm a bit of a newbie to C# programming so forgive this innocent question, but coming from a C++ background this seems very odd to me, and I'm hoping someone can shed some light...
0
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that...
1
by: Ezmeralda | last post by:
Hello, I need to an TCP/IP Interface for communication with an embedded device. Since I have two different design ideas in mind, I am wondering whether you could give me some hints to decide:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.