本文介绍了如何将列表类转换为类数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public class PGNsegmentTxMap
{
string pgn;
public string segmentTx { get; set; }
public string PGN
{
get
{
if (!String.IsNullOrEmpty(pgn))
return pgn.ToUpper();
else
return string.Empty;
}
set { pgn = value; }
}
public PGNsegmentTxMap(string pgn, string segmentTx)
{
this.segmentTx = segmentTx;
this.pgn = pgn;
}
}
#endregion
class ProductComparer : IEqualityComparer<PGNsegmentTxMap>
{
// Products are equal if their names and product numbers are equal.
public bool Equals(PGNsegmentTxMap x, PGNsegmentTxMap y)
{
//Check whether the compared objects reference the same data.
if (Object.ReferenceEquals(x, y)) return true;
//Check whether any of the compared objects is null.
if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
return false;
//Check whether the products' properties are equal.
return x.segmentTx == y.segmentTx && x.PGN == y.PGN;
}
public int GetHashCode(PGNsegmentTxMap product)
{
//Check whether the object is null
if (Object.ReferenceEquals(product, null)) return 0;
//Get hash code for the Name field if it is not null.
int hashProductName = product.segmentTx == null ? 0 : product.segmentTx.GetHashCode();
//Get hash code for the Code field.
int hashProductCode = product.PGN.GetHashCode();
//Calculate the hash code for the product.
return hashProductName ^ hashProductCode;
}
}
推荐答案
PGNsegmentTxMap[] products = PGNsegmentMapLists.ToArray();
这篇关于如何将列表类转换为类数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!