关于接口实现问题
接口定义Imports System.Collections.Generic
Imports System.Text
Imports System.Collections
Namespace Generic
Public Inte易做图ce IDiscuzCollection(Of T)
Inherits ICollection(Of T)
Inherits IComparable
''' <summary>
''' 固定大小
''' </summary>
Property FixedSize() As Integer
''' <summary>
''' 集合类是否为空
''' </summary>
ReadOnly Property IsEmpty() As Boolean
''' <summary>
''' 集合类是否已满
''' </summary>
ReadOnly Property IsFull() As Boolean
''' <summary>
''' 版本
''' </summary>
ReadOnly Property Version() As String
''' <summary>
''' 作者
''' </summary>
ReadOnly Property Author() As String
End Inte易做图ce
Public Inte易做图ce IDiscuzVisitor(Of T)
''' <summary>
''' 是否已运行
''' </summary>
ReadOnly Property HasDone() As Boolean
''' <summary>
''' 访问指定的对象
''' </summary>
Sub Visit(ByVal obj As T)
End Inte易做图ce
End Namespace
实现
Imports System.Collections.Generic
'Imports System.Runtime.Serialization
Imports System.Text
Namespace Generic
''' <summary>
''' 队列泛型类
''' </summary>
''' <typeparam name="T">占位符(下同)</typeparam>
<Serializable()> _
Public Class Queue(Of T)
Inherits System.Collections.Generic.Queue(Of T)
Implements IDiscuzCollection(Of T)
#Region "构造函数"
Public Sub New()
MyBase.New()
End Sub
Public Sub New(ByVal collection As IEnumerable(Of T))
MyBase.New(collection)
End Sub
Public Sub New(ByVal capacity As Integer)
MyBase.New(capacity)
End Sub
#End Region
'Sub clear() Implements ICollection(Of T).Clear
'End Sub
''' <summary>
''' 返回当前实例
''' </summary>
Public ReadOnly Property SyncRoot() As Object
Get
Return Me
End Get
End Property
''' <summary>
''' 是否为空
''' </summary>
Public ReadOnly Property IsEmpty() As Boolean Implements IDiscuzCollection(Of T).IsEmpty
Get
Return Me.Count = 0
End Get
End Property
Private _fixedsize As Integer = 0
''' <summary>
''' 固定大小属性
''' </summary>
Public Property FixedSize() As Integer Implements IDiscuzCollection(Of T).FixedSize
Get
Return _fixedsize
End Get
Set(ByVal value As Integer)
_fixedsize = value
End Set
End Property
''' <summary>
''' 当前队列是否已满
''' </summary>
Public ReadOnly Property IsFull() As Boolean Implements IDiscuzCollection(Of T).IsFull
Get
If (FixedSize <> 0) AndAlso (Me.Count >= FixedSize) Then
Return True
Else
Return False
End If
End Get
End Property
''' <summary>
''' 版本
''' </summary>
Public ReadOnly Property Version() As String Implements IDiscuzCollection(Of T).Version
Get
Return "1.0"
End Get
End Property
''' <summary>
''' 作者
''' </summary>
Public ReadOnly Property Author() As String Implements IDiscuzCollection(Of T).Author
Get
Return "Rainboy"
End Get
End Property
''' <summary>
''' 接受指定的访问方式(访问者模式)
''' </summary>
''' <param name="visitor"></param>
Public Sub Accept(ByVal visitor As IDiscuzVisitor(Of T))
If visitor Is Nothing Then
Throw New ArgumentNullException("访问对象为空")
End If
Dim enumerator As System.Collections.Generic.Queue(Of T).Enumerator = Me.GetEnumerator()
While enumerator.MoveNext()
visitor.Visit(enumerator.Current)
If visitor.HasDone Then
Return
End If
End While
End Sub
''' <summary>
''' 追加元素
''' </summary>
''' <param name="value"></param>
Public Shadows Sub Enqueue(ByVal value As T)
If Not Me.IsFull Then
MyBase.Enqueue(value)
End If
End Sub
Private Function ICollection_Remove(ByVal item As T) As Boolean Implements ICollection(Of T).Remove
Throw New NotSupportedException()
End Function
Private Sub ICollection_Add(ByVal item As T) Implements ICollection(Of T).Add
Throw New NotSupportedException()
End Sub
''' <summary>
''' 比较对象
''' </summary>
''' <param name="obj"></param>
''' <returns></returns>
Public Function CompareTo(ByVal obj As Object) As Integer Implements IDiscuzCollection(Of T).CompareTo
If obj Is Nothing Then
Throw New ArgumentNullException("比较对象为空")
End If
If obj.[GetType]() Is Me.[GetType]() Then
Dim d As Queue(Of T) = TryCast(obj, Queue(Of T))
Return Me.Count.CompareTo(d.Count)
Else
Return Me.[GetType]().FullName.CompareTo(obj.[GetType]().FullName)
End If
End Function
''' <summary>
''' 是否只读
''' </summary>
Public ReadOnly Property IsReadOnly() As Boolean Implements IDiscuzCollection(Of T).IsReadOnly
Get
Return False
End Get
End Property
End Class
End Namespace
错误 16 Class“Queue”必须为接口“System.Collections.Generic.ICollection(Of T)”实现“Function Contains(item As T) As Boolean”。 D:\HZBBS\Common\Generic\DiscuzQueue.vb 13 20 Common
错误 17 Class“Queue”必须为接口“System.Collections.Generic.ICollection(Of T)”实现“ReadOnly Property Count As Integer”。实现属性必须有匹配的“ReadOnly”或“WriteOnly”说明符。 D:\HZBBS\Common\Generic\DiscuzQueue.vb 13 20 Common
错误 18 Class“Queue”必须为接口“System.Collections.Generic.ICollection(Of T)”实现“Sub Clear()”。 D:\HZBBS\Common\Generic\DiscuzQueue.vb 13 20 Common
错误 19 Class“Queue”必须为接口“System.Collections.Generic.ICollection(Of T)”实现“Sub CopyTo(array() As T, arrayIndex As Integer)”。 D:\HZBBS\Common\Generic\DiscuzQueue.vb 13 20 Common
请问这是怎么一回事儿? --------------------编程问答-------------------- C#中实现没问题,我是将Discuznt3。5中的代码转成vb时出现的问题 --------------------编程问答-------------------- 这些好像基类已经实现了呀
--------------------编程问答-------------------- 没有实现接口要求的函数
接口成员必须在类中全部都实现 --------------------编程问答-------------------- using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace Discuz.Common.Generic
{
public inte易做图ce IDiscuzCollection<T> : ICollection<T>, IComparable
{
/// <summary>
/// 固定大小
/// </summary>
int FixedSize { get;}
/// <summary>
/// 集合类是否为空
/// </summary>
bool IsEmpty { get;}
/// <summary>
/// 集合类是否已满
/// </summary>
bool IsFull { get;}
/// <summary>
/// 版本
/// </summary>
string Version {get;}
/// <summary>
/// 作者
/// </summary>
string Author {get;}
}
public inte易做图ce IDiscuzVisitor<T>
{
/// <summary>
/// 是否已运行
/// </summary>
bool HasDone { get; }
/// <summary>
/// 访问指定的对象
/// </summary>
void Visit(T obj);
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Discuz.Common.Generic
{
/// <summary>
/// 队列泛型类
/// </summary>
/// <typeparam name="T">占位符(下同)</typeparam>
[Serializable]
public class Queue<T> : System.Collections.Generic.Queue<T>, IDiscuzCollection<T>
{
#region 构造函数
public Queue() : base()
{ }
public Queue(IEnumerable<T> collection) : base(collection)
{ }
public Queue(int capacity)
: base(capacity)
{ }
#endregion
/// <summary>
/// 返回当前实例
/// </summary>
public object SyncRoot
{
get
{
return this;
}
}
/// <summary>
/// 是否为空
/// </summary>
public bool IsEmpty
{
get
{
return this.Count == 0;
}
}
private int _fixedsize = default(int);
/// <summary>
/// 固定大小属性
/// </summary>
public int FixedSize
{
get
{
return _fixedsize;
}
set
{
_fixedsize = value;
}
}
/// <summary>
/// 当前队列是否已满
/// </summary>
public bool IsFull
{
get
{
if ((FixedSize != default(int)) && (this.Count >= FixedSize))
{
return true;
}
else
{
return false;
}
}
}
/// <summary>
/// 版本
/// </summary>
public string Version
{
get
{
return "1.0";
}
}
/// <summary>
/// 作者
/// </summary>
public string Author
{
get
{
return "Discuz!NT";
}
}
/// <summary>
/// 接受指定的访问方式(访问者模式)
/// </summary>
/// <param name="visitor"></param>
public void Accept(IDiscuzVisitor<T> visitor)
{
if (visitor == null)
{
throw new ArgumentNullException("访问对象为空");
}
System.Collections.Generic.Queue<T>.Enumerator enumerator = this.GetEnumerator();
while (enumerator.MoveNext())
{
visitor.Visit(enumerator.Current);
if (visitor.HasDone)
{
return;
}
}
}
/// <summary>
/// 追加元素
/// </summary>
/// <param name="value"></param>
public new void Enqueue(T value)
{
if (!this.IsFull)
{
base.Enqueue(value);
}
}
bool ICollection<T>.Remove(T item)
{
throw new NotSupportedException();
}
void ICollection<T>.Add(T item)
{
throw new NotSupportedException();
}
/// <summary>
/// 比较对象
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public int CompareTo(object obj)
{
if (obj == null)
{
throw new ArgumentNullException("比较对象为空");
}
if (obj.GetType() == this.GetType())
{
Queue<T> d = obj as Queue<T>;
return this.Count.CompareTo(d.Count);
}
else
{
return this.GetType().FullName.CompareTo(obj.GetType().FullName);
}
}
/// <summary>
/// 是否只读
/// </summary>
public bool IsReadOnly
{
get
{
return false;
}
}
}
}
上面是C#的代码,可我没发现实现呀,所以我想应该在基类中实现了 --------------------编程问答-------------------- 直接用 c# 的封装个dll给vb.net用好么? --------------------编程问答-------------------- 我主要想知道为什么 --------------------编程问答--------------------
补充:.NET技术 , VB.NET