|
You don't call an interfaces function as it provides no implementation.
In your example any instance of class A is also intf1 and intf2, but the get method used is the class instance's implementation.
If you want differering implementations, you can declare one or more of them explicitly.
void intf1.get()
{
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
I'm declaring my function(s) as given below but now it's letting me to create an instance of the function(s) to call
interface intf1
{
void get(int a);
}
interface intf2
{
void get(int a);
}
class A : intf1,intf2
{
void intf1.get(int a)
{
Console.WriteLine(a);
}
void intf2.get(int a)
{
Console.Write(a);
}
}
A e = new A();
//How to intf1.get(....) and intf2.get(....)
|
|
|
|
|
There's several ways.
(Example 1)
If you're absolutely sure that A implements the interface in question then you can do an implicit conversion).
(Example 2)
Normally it's better to check first. Also, if you don't want to keep a new object then you can explicitly cast and call the method.
A a = new A();
intf1 a1 = a;
a1.get(1);
if (a is intf2)
{
((intf2)a).get(2);
} Incedently, it's better to stick with general naming conventions i.e.
interface IMyRandomInterface{ ... }
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
modified on Wednesday, March 25, 2009 12:40 PM
|
|
|
|
|
Yes, it's rocking but can you explain your last post a bit more
You don't call an interfaces function as it provides no implementation.
In your example any instance of class A is also intf1 and intf2, but the get method used is the class instance's implementation.
which get() method is called, of both interfaces or a class instance.
Actually, if we don't implement function(s) defined in interfaces, it arises exception
|
|
|
|
|
don't be lazy, read a book and perform an experiment. You could find out in a matter of minutes.
.NET- India wrote: it arises exception
No exception, it's a compiler-generated error message.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
It's because of the two different methods of implementing.
You can implement an interface implicitly or explicitly. Consider the sample below. IMyFirstInterface is implemented implicitly. That is the implementation that will implicitly be used unless you explicitly state otherwise.
IMySecondInterface is implemented explicitly - you have to explicitly state that you want to use that implementation.
MyImplementingClass implementingClass = new MyImplementingClass();
implementingClass.Method(1);
if (implementingClass is IMySecondInterface)
{
((IMySecondInterface)implementingClass).Method(1);
}
public class MyImplementingClass : IMyFirstInterface, IMySecondInterface
{
#region IMyFirstInterface Members
public void Method(int value)
{
Console.WriteLine(value);
}
#endregion
#region IMySecondInterface Members
void IMySecondInterface.Method(int value)
{
Console.WriteLine("Value = {0}", value);
}
#endregion
}
public interface IMyFirstInterface
{
void Method(int value);
}
public interface IMySecondInterface
{
void Method(int value);
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
DaveyM69 wrote: (Example 1)
If you're absolutely sure that A implements the interface in question then you can do an implicit conversion).
The compiler takes care of ensuring that A implements the interface, doesn't it? Otherwise it wouldn't let the implicit conversion succeed.
|
|
|
|
|
Correct - of course!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
"An interface is a contract that guarantees to a client how a class or struct will behave. When a class implements an interface, it tells any potential client "I guarantee that I'll support the methods, properties, events, and indexers of the named interface"
So it does not contain any executable code. The method which is getting called is the method what you have implemented. In this case the get()
There may be a question arise when both the interfaces have same method name, return type, argument list and both the methods should be implemented.
At that time you can specify the interface name prior to the definition.
Have a Happy Coding.....
|
|
|
|
|
I want to fill combo box with the values in Excel usind ADO.NET and C# i have written a code bit its not working. Kindly help.
private void FillAccounts()
{
try
{
string excelFile = @"C:\Capacity Planning\Accounts.xls";
//String sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " + @"C:\Capacity Planning\Accounts.xls" + ";Extended Properties=Excel 12.0 Xml;HDR=YES;:Max Buffer Size=256;";
String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + excelFile + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'";
OleDbConnection objConn = new OleDbConnection(sConnectionString);
objConn.Open();
OleDbCommand objCmdSelect = new OleDbCommand("SELECT Account,Link FROM [Accounts$]", objConn);
OleDbDataAdapter objAdapter = new OleDbDataAdapter();
objAdapter.SelectCommand = objCmdSelect;
DataSet objDataset = new DataSet();
objAdapter.Fill(objDataset);
cbAccounts.DataSource = objDataset.Tables["Accounts"];
cbAccounts.DisplayMember = "Account";
cbAccounts.ValueMember = "Accounts.Account";
objConn.Close();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
Thanks a lot in advance
shantanu
|
|
|
|
|
Hi
When changing a value in any cell in DataGridView , this value is saved into the related dataset only after the user clicks on an other cell in an other row !
Even the mecthod AcceptChanges() will not save the contents of this cell unless the user moves to an other row . I need to save these contents straight away without forcing the user to leave the cell .
any Ideas ?
thanx .
|
|
|
|
|
unitecsoft wrote: without forcing the user to leave the cell
How will you know when the user is finished with editing then? Saving the current value at each keypress is going to be inefficient
I are troll
|
|
|
|
|
the problem is even if you save by clicking a SAVE button which will fire AcceptCanges() method , the contents of the cell are not saved unless the user previously leaves the row which include that cell .
|
|
|
|
|
If he clicks a save-button, doesn't that move the focus to the button (and out of the cell, triggering validates and such)?
I are troll
|
|
|
|
|
Yes , but does not save the value of that cell !!! I don't know why !!!
the only way to save it is to click a different ROW within the grid .
|
|
|
|
|
That shouldn't be happening, according to the documentation;
"When you call AcceptChanges on the DataSet, any DataRow objects still in edit-mode end their edits successfully." (Source[^])
Can you post the offending code?
I are troll
|
|
|
|
|
Hi all...
I've got a problem with a crystal report app (Delphi) and I need Help. I got the following code to work on two machines but it keeps failing on the client server. Can someone tell me why. PS The client server works with a XBase driver the two Machines I got it to work on runs a foxpro driver. That is the only thing I can pick up thats different...
dtmVision.crGeneric.Tables.ItemIndex :=0;
dtmVision.crGeneric.Tables.Item.Name :='System.dbf';
dtmVision.crGeneric.Tables.ItemIndex :=0;
dtmVision.crGeneric.Tables.Item.Path :=sDBPathForVision;
dtmVision.crGeneric.Tables.ItemIndex:=1;
dtmVision.crGeneric.Tables.Item.Name:='Customer.dbf';
dtmVision.crGeneric.Tables.ItemIndex :=1;
dtmVision.crGeneric.Tables.Item.Path :=sDBPathForVision;
dtmVision.crGeneric.Tables.ItemIndex := 2;
dtmVision.crGeneric.Tables.Item.Name :=sFnTempTRans;
dtmVision.crGeneric.Tables.ItemIndex :=2;
dtmVision.crGeneric.Tables.Item.Path :=ExtractFilePath(sFnTempTRans);
crGeneric is of type TCrpe
Stephen Lintott Bsc IT (RAU)
|
|
|
|
|
Sorry wrong form ignore this post please
Stephen Lintott Bsc IT (RAU)
|
|
|
|
|
download the checked record from the gridview using c#
|
|
|
|
|
Is this a question?
I assume that the checked record represents a file or sth similar. If you press a button like "Download" you can catch the event in your code behind and send the file content as response.
Regards
Sebastian
|
|
|
|
|
when i click download button the checked file in gridview will download using asp.net and c#
|
|
|
|
|
Now, which seems more likely to you - that this question will be answered in the C# forum where lots of people have NO knowledge of ASP.NET, or the ASP.NET forum?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys
|
|
|
|
|
|
Rahad Rahman wrote: give me solution
Get stuffed. If you can't use google, can't read a book, can't use intellisense, have no idea how C# or winforms works, and can't even ask nicely, then why should we help you ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hear hear.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|