是System.Collections.Generic.List<T>一种链表(不是LinkedList<T>类)?
甲链表是由一组一起代表一个序列节点中的数据结构.在最简单的形式下,每个节点由一个数据和一个到序列中下一个节点的引用(换句话说,一个链接)组成.
链接列表,其节点包含两个字段:整数值和指向下一个节点的链接.
最后一个节点链接到用于表示列表末尾的终止符.wikipedia.org
如果是,它是什么样的链表?
我有一个这样的集合类:
public class SomeDataCollection : List<ISomeData>
{
// some method ...
}
Run Code Online (Sandbox Code Playgroud)
但我不能这样做:
SomeDataCollection someDatas = new List<ISomeData>();
Run Code Online (Sandbox Code Playgroud)
无法隐式转换
List<ISomeData>为SomeDataCollection.存在显式转换(您是否错过了演员?)
所以我尝试在SomeDataCollection集合类中创建一个隐式的转换器:
public static implicit operator SomeDataCollection(List<ISomeData> l)
{
var someDatas = new SomeDataCollection();
someDatas.AddRange(l);
return someDatas;
}
Run Code Online (Sandbox Code Playgroud)
但它说我不能创建这样的转换器:
SomeDataCollection.implicit operator SomeDataCollection(List<ISomeData>):不允许在基类之间进行用户定义的转换
当我这样投出时:
SomeDataCollection someDatas = (SomeDataCollection)new List<ISomeData>();
Run Code Online (Sandbox Code Playgroud)
它抛出一个错误,说:
System.InvalidCastException:无法将类型的对象强制转换
List<ISomeData>为类型SomeDataCollection.
我怎样才能做到这一点:
SomeDataCollection someDatas = new List<ISomeData>();
Run Code Online (Sandbox Code Playgroud)
没有收到错误?请帮忙.提前致谢.
当我声明这样的方法时:
void DoWork<T>(T a) { }
void DoWork(int a) { }
Run Code Online (Sandbox Code Playgroud)
并称之为:
int a = 1;
DoWork(a);
Run Code Online (Sandbox Code Playgroud)
DoWork它会采用什么方法,为什么?我似乎无法在任何MSDN文档中找到它.
我在observable集合的xml序列化中遇到问题.
这是我序列化的内容:
public enum Status { Pending, Active, Completed, Cancelled }
public abstract class Entity : INotifyPropertyChanged
{
...
}
public class UserStory : Entity
{
public uint StoryID { get; set; }
public Status Status { get; set; }
...
public ObservableCollection<Task> Tasks { get; set; }
}
public class Task : Entity
{
public uint TaskID { get; set; }
...
}
Run Code Online (Sandbox Code Playgroud)
这是我如何序列化它:
public static void SerializeObjectToXML<T>(T item, string FilePath)
{
XmlSerializer xs = new XmlSerializer(typeof(T));
using (StreamWriter …Run Code Online (Sandbox Code Playgroud) 我的WCF服务中有这个代码:
public class MyImage
{
public Image Image { get; set; }
public string FullPath { get; set; }
}
[ServiceContract]
public interface IMyService
{
[OperationContract] void SaveImage(MyImage myImg);
}
public class MyService : IMyService
{
public void SaveImage(MyImage myImg)
{
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行SaveImage()方法时会发生此错误:
尝试序列化参数http://tempuri.org/:e时出错.InnerException消息是' Type'System.Drawing.Bitmap',数据协定名称为'Bitmap:http://schemas.datacontract.org/2004/07/System.Drawing'不是预期的.考虑使用DataContractResolver或添加静态已知的已知类型的列表中的任何类型的不-例如,通过使用KnownTypeAttribute属性或将它们添加到已知类型传递给DataContractSerializer的名单"
我的代码在C#,Framework 4.0中,在Visual Studio 2010 Pro中构建.
请提前帮助,谢谢.
我List<string>使用这段代码序列化了一个非常大的:
public static string SerializeObjectToXML<T>(T item)
{
XmlSerializer xs = new XmlSerializer(typeof(T));
using (StringWriter writer = new StringWriter())
{
xs.Serialize(writer, item);
return writer.ToString();
}
}
Run Code Online (Sandbox Code Playgroud)
并使用此代码反序列化它:
public static T DeserializeXMLToObject<T>(string xmlText)
{
if (string.IsNullOrEmpty(xmlText)) return default(T);
XmlSerializer xs = new XmlSerializer(typeof(T));
using (MemoryStream memoryStream = new MemoryStream(new UnicodeEncoding().GetBytes(xmlText.Replace((char)0x1A, ' '))))
using (XmlTextReader xsText = new XmlTextReader(memoryStream))
{
xsText.Normalization = true;
return (T)xs.Deserialize(xsText);
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我反序列化时,我得到了这个异常:
XMLException:XML文档中存在错误(217388,15).'[]',十六进制值0x1A,是无效字符.第217388行,第15位.
在System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader,String encodingStyle,XmlDeserializationEvents事件)
在System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader)
为什么 xmlText.Replace((char)0x1A, ' ') …
如何获得TypeID具有最大值的不同行EffectivityDate?
-----------------------------------------
| ID | TypeID | Value | EffectivityDate |
-----------------------------------------
| 1 | 1 | 2.3 | 1990-01-01 |
| 2 | 1 | 3.4 | 1999-10-31 |
| 3 | 2 | 1.1 | 1990-01-01 |
| 4 | 2 | 2.2 | 1999-10-31 |
| 5 | 3 | 6.1 | 1999-10-31 |
-----------------------------------------
Run Code Online (Sandbox Code Playgroud)
-----------------------------------------
| ID | TypeID | Value | EffectivityDate |
-----------------------------------------
| 2 | 1 | …Run Code Online (Sandbox Code Playgroud) 我有这样的代码:
public static void ToUpperCase(params Control[] controls)
{
foreach (Control oControl in controls)
{
if (oControl is TextBox)
{
oControl.TextChanged += (sndr, evnt) =>
{
TextBox txtControl = sndr as TextBox;
int pos = txtControl.SelectionStart;
txtControl.Text = txtControl.Text.ToUpper();
txtControl.SelectionStart = pos;
};
}
else if (oControl is ComboBox)
{
oControl.TextChanged += (sndr, evnt) =>
{
ComboBox cmbControl = sndr as ComboBox;
int pos = cmbControl.SelectionStart;
cmbControl.Text = cmbControl.Text.ToUpper();
cmbControl.SelectionStart = pos;
};
}
else throw new NotImplementedException(oControl.GetType().DeclaringType.ToString() + " is …Run Code Online (Sandbox Code Playgroud) 每当调用同一个类中的方法时,如何在类中调用方法?
而不是这样做:
public class MyClass
{
private void InvokeMe() { }
public void Method1()
{
this.InvokeMe();
// some codes
}
public void Method2()
{
this.InvokeMe();
// some codes
}
public void Method3()
{
this.InvokeMe();
// some codes
}
// more methods
}
Run Code Online (Sandbox Code Playgroud)
我想自动调用InvokeMe私有方法,而不是将它放在MyClass中的每个公共方法上,因为我们在该类中有太多方法,并且该类总是更改.
我的代码在C#,Framework 4.0中,在Visual Studio 2010 Pro中构建.
请帮助,提前致谢.
我正在从WCF服务应用程序开发Web服务,并且运行Visual Studio 2010 Pro,并localhost:<port>/<service>在同一解决方案中从Windows窗体项目引用Visual Studio创建的内容。
Visual Studio如何在不安装Web服务的情况下在本地运行Web服务?我可以使用相同的方法部署Web服务吗?