Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
An interface contain 4 methods , but i want to implement only 2 methods.

I know upto we must implement. I'm just asking: is there any way?
Posted
Updated 7-Jun-12 0:41am
v2
Comments
Maciej Los 7-Jun-12 6:38am    
Not clear! Please, be more specific, provide more details and show us what you have done till now.
RDBurmon 8-Jun-12 8:30am    
Thanks Everyone who replied to this thread , So OP , I think you have got enough response and you should be able to mark it as your answer and close the thread.

Create the method footprint of the unwanted methods in your implementation and do nothing in the method. I don't think it is the right thing to do but it will work.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Jun-12 1:26am    
Not always. It all depends on purpose. What you advice is called pseudo-abstract method.
--SA
Difinitly we can not miss those two method from implementing. This what for the interfaces are .
 
Share this answer
 
Implement you interface in abstract class.and make methods that you do not want to implement abstract.
like
C#
Interface tt
{
void m1();
void m2();

}
abstract class c1:tt
{
public void m1()
{
.
.
.
}

public abstract void m2();
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-Jun-12 1:24am    
Note, you do not explain how it further can be used. Please note that the OP's level is quite low, so I would worry about understanding of this otherwise correct post.
--SA
jameschowdaree 26-Jun-12 10:07am    
here i got it.

thanks umashanker patel.
The purpose of an interface is ensure that anything derived from the interface has the methods and properties (plus other stuff) associated with the interface. Thus when you cast an object to an interface, the compiler knows that that object, if the cast is successful, will have those methods and properties. SOrt of defeat the purpose of deriving from and interface if those methods and properties do not exist. Normally what you do if you do not want to implement those methods or properties is that you have the property or method throw a NotImplementedExcedption. That way you guarentee that there is no attempt to use them.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900