|
Interfaces are only "contracts" that a class has some methods that can be called, regardless of the actual implementation of the class.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Right, but what about writing the signature of the overloading methods inside the interface and the implementation inside the object itself?
|
|
|
|
|
You can't declare abstract static methods inside an interface, and overloads are static methods.
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 Tuesday, January 27, 2009 6:54 AM
|
|
|
|
|
As everyone said, interfaces can't contain static methods. BTW, what are you trying to achieve?
|
|
|
|
|
I thought of creating a class that implements MyComparable and that instances of this class will be able to compare themselves. It's more for practicing, than a "real world" problem. I thought to declare the overloads in this interface (instead of use the CompareTo()).
I guess that what I'm really asking is how to compare objects without using IComparable, but with overloads.
Thanks,
Vered
|
|
|
|
|
You really should read the article[^] that I linked to previously, especially the section on Comparison Operators. All the information is in there.
Anyway, all you need to do is to implement overloads for < and > in your class. How you implement these is up to you, it very much depends on the data structure of your class and is not suitable for many classes. If you're implementing one of these operators, you MUST implement the second. The == and != operators are not necessarily required in your case, but if you choose to implement them you should override Equals and GetHashCode too.
Once you have < and > you can have your own CompareTo method that simply tests < and returns -1 if true, > and returns 1 if true, otherwise returns 0 (equal). I've given an example below. I've implemented IComparable too for completeness. The class just wraps a single Int32, obviously a real world example would be more complex.
using System;
public class MyClass : IComparable
{
#region Constructors
public MyClass(int value)
{
Value = value;
}
#endregion
#region Properties
public int Value
{
get;
set;
}
#endregion
#region Comparison Operator Overloads
public static bool operator <(MyClass instanceA, MyClass instanceB)
{
return (instanceA.Value < instanceB.Value);
}
public static bool operator >(MyClass instanceA, MyClass instanceB)
{
return (instanceA.Value > instanceB.Value);
}
#endregion
#region Compare Methods
public int CompareTo(MyClass other)
{
if (this < other)
return -1;
else if (this > other)
return 1;
else
return 0;
}
#endregion
#region IComparable Members
public int CompareTo(object obj)
{
if (obj is MyClass)
return this.CompareTo((MyClass)obj);
return 1;
}
#endregion
}
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 Tuesday, January 27, 2009 2:10 PM
|
|
|
|
|
'\0'
is the above command valid for calculating end of line in while loop...
if not wat should be used to EOF identification
the quieter u become more u hear
|
|
|
|
|
Hi,
as far as I know does the .NET-Framework abstracts the issue of string termination. If you read from a file for example, you can use the StreamReader.ReadLine(). This will read a whole line...
Regards
Sebastian
|
|
|
|
|
Are you looking for the "End of String", or "End of File"?
I are troll
|
|
|
|
|
end of string
the quieter u become more u hear
|
|
|
|
|
Use String.Length to locate the end of the string.
I are troll
|
|
|
|
|
lawrenceinba wrote: '\0'
is the above command valid for calculating end of line in while loop...
I have never seen any system where the NUL character is used as end of line. It's commonly used as end of string in systems that doesn't have a String object that keeps track of the length.
lawrenceinba wrote: if not wat should be used to EOF identification
The '\x1a' character is the EOF marker, however .NET doesn't use any EOF marker.
You should ask about what you are trying to do instead of asking about some obsolete techniques that doesn't apply to C#.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
i'll give input to a while loop....it should exit at end of string
this is what i need
the quieter u become more u hear
|
|
|
|
|
If you want to loop through the characters in a string, you can use the enumerator or the Length property:
foreach (char c in daString) {
Console.WriteLine(c);
}
for (int i = 0; i < daString.Length; i++) {
Console.WriteLine(daString[i]);
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
can we do row span and column span of c# datagrid.i want to split my columns to look like
name
first last
|
|
|
|
|
You can override paint event and draw manually.
|
|
|
|
|
Hi,
I'm assigning an URL to clipboard and when i paste that to Word document that becomes normal text, How can i retain that as a URL?
Thanks
|
|
|
|
|
It's a bit of a pain - basically you need to format the next in "HTML Clipboard Format" ( link[^] ) - it's the bit between StartFragment and EndFragment that actually gets pasted into Word
|
|
|
|
|
Hi,
I have Listbox(lstgroups) and listview(lstItems). say items in lisbox as Groups and in listview as Items.
Each Group should have list of items, when i add an new item to lstitems. it should assign to selected group. and If I add two items to a selected group and moved to Second goup and added items to these. Then if moved to first group the intial added Items are to displayed in Listview. is that Possible.
By using dictionary classes
Here List<object> should return lstitems
Dictionary<string, List<object>> d= new Dictionary(string, List<object>>();
d.add(lstgroups.items, new List<object>);
//error cumes here, how to assign here List<>
Thanks and regards,
Uday
|
|
|
|
|
I don't understand what the problem is :-
Dictionary<string,>> d = new Dictionary<string,>>();
List<object> list = new List<object>();
list.Add("Item1");
list.Add("Item2");
list.Add("Item3");
d.Add("ItemGroup1", list);
|
|
|
|
|
Hello All,
I want to read all mail of one folder from outlook and here is code at which line i am getting error....
Outlook.Items MailItems;
MailItems = .......
for (int i = MailItems.Count; i >= 1; i += -1)
{
Outlook.MailItem mitem;
mitem = (Outlook.MailItem)MailItems.Item(i); }
When casting getting below exception..
Tried lot from Google and other sites not getting appropriate solution.
Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Outlook.MailItem'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00063034-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."
Thanks,
Sun Rays
To get something you must have to try once.
My Articles
|
|
|
|
|
Were you able to figure this out? I am having the smae problem on undeliverable emails that are bounced back to the inbox.
thanks
dennis
|
|
|
|
|
The below section should assist anyone attempting to use the MailItem object.
The key to this code not throwing exceptions is that the items collection may
contain more than just MailItems and therefore the following code allows you
to retrieve just the MailItems from the collection.
Outlook.Application olApp = new Outlook.Application();
Outlook.MAPIFolder inBox = (Outlook.MAPIFolder)olApp.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items Inboxitems = inBox.Items;
foreach (Outlook.MailItem item in Inboxitems.OfType<Outlook.MailItem>())
{
InboxSize = InboxSize + item.Size;
}
Obviously once you have a handle to the individual Mailitem you can access all of it's properties.
Happy Coding
|
|
|
|
|
i want to extract attachments stored in xml in document tag on my local pc
|
|
|
|
|
Reetu Singh wrote: extract attachments stored in xml
How XML file can store other documents? Your question is not clear. Please explain it clearly.
|
|
|
|