当前位置: 首页>>代码示例>>C#>>正文


C# Array.Cast方法代码示例

本文整理汇总了C#中System.Array.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# Array.Cast方法的具体用法?C# Array.Cast怎么用?C# Array.Cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Array的用法示例。


在下文中一共展示了Array.Cast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: QTable

        /// <summary>
        ///     Initializes a new instance of the QTable with specified column names and data matrix.
        /// </summary>
        public QTable(string[] columns, Array data)
        {
            if (columns == null || columns.Length == 0)
            {
                throw new ArgumentException("Columns array cannot be null or 0-length");
            }

            if (data == null || data.Length == 0)
            {
                throw new ArgumentException("Data matrix cannot be null or 0-length");
            }

            if (columns.Length != data.Length)
            {
                throw new ArgumentException("Columns array and data matrix cannot have different length");
            }

            if (data.Cast<object>().Any(col => !col.GetType().IsArray))
            {
                throw new ArgumentException("Non array column found in data matrix");
            }

            columnsMap = new ListDictionary();
            for (int i = 0; i < columns.Length; i++)
            {
                columnsMap[columns[i]] = i;
            }

            this.columns = columns;
            this.data = data;
            RowsCount = ((Array)data.GetValue(0)).Length;
        }
开发者ID:CharlesSkelton,项目名称:qSharp,代码行数:35,代码来源:QTable.cs

示例2: FormatParameter

        public string FormatParameter(string name, Array values, Func<object, string> valueFormatter)
        {
            var items = string.Join(",", values.Cast<object>()
                .Select(valueFormatter));

            return string.Concat(name, "=", items);
        }
开发者ID:jonnii,项目名称:SpeakEasy,代码行数:7,代码来源:CommaSeparatedArrayFormatter.cs

示例3: StandardValuesConverter

 /// <summary>
 /// Constructor</summary>
 /// <param name="values">Values to include in the collection</param>
 public StandardValuesConverter(Array values)
 {
     if (values == null)
         throw new ArgumentNullException("values");
     m_values = new StandardValuesCollection(values);
     
     // Check if all items are exclusive using a hash set
     var set = new HashSet<object>();
     m_exclusive = values.Cast<object>().All(set.Add); 
 }
开发者ID:Joxx0r,项目名称:ATF,代码行数:13,代码来源:StandardValuesConverter.cs

示例4: AddRange

        public override void AddRange(Array values)
        {
            var paramaters = values.Cast<CrmParameter>().ToList();
            bool canAdd = paramaters.Aggregate(true, (current, crmParameter) => current && crmParameter.CanAddToCommand());

            if (canAdd)
            {
                _Params.AddRange(paramaters);
            }
            else
            {
                throw new ArgumentException("one or more of the parameters in the array are not valid to add to a command. Are they all named?");
            }
        }
开发者ID:YOTOV-LIMITED,项目名称:CrmAdo,代码行数:14,代码来源:CrmParameterCollection.cs

示例5: GetBytes

 public static byte[] GetBytes(Array array, Encoding encoding)
 {
     if (array == null)
         return null;
     var bytes = array as byte[];
     if (bytes != null)
         return bytes;
     var objects = array.Cast<object>();
     var first = objects.FirstOrDefault();
     if (first.GetBaseObject().GetType().IsPrimitive) {
         return objects.Select(item => Convert.ToByte(item.GetBaseObject())).ToArray();
     } else {
         var text = new StringBuilder();
         foreach (var entry in array) {
             if (text.Length > 0)
                 text.AppendLine();
             var item = entry.GetBaseObject();
             if (item != null)
                 text.Append(item);
         }
         return encoding.GetBytes(text.ToString());
     }
 }
开发者ID:prantlf,项目名称:SharePosh,代码行数:23,代码来源:ConvertToBytes.cs

示例6: AddRange

 public override void AddRange(Array values) => Add(values.Cast<SqliteParameter>());
开发者ID:leloulight,项目名称:Microsoft.Data.Sqlite,代码行数:1,代码来源:SqliteParameterCollection.cs

示例7: InvalidValueException

 public static TagException InvalidValueException(object value, Array possibleValues)
 {
     return new TagException($"Value '{value}' is not allowed. Possible values are: {string.Join(", ", possibleValues.Cast<object>().Select(v => v.ToString()))}");
 }
开发者ID:rslijp,项目名称:sharptiles,代码行数:4,代码来源:EnumTagAttributeValidator.cs

示例8: AddRange

		public override void AddRange(Array values)
		{
			AddRange(values.Cast<object>().Select(x => { EnsureFbParameterType(x); return (FbParameter)x; }));
		}
开发者ID:fishcodelib,项目名称:FirebirdSql.Data.FirebirdClient,代码行数:4,代码来源:FbParameterCollection.cs

示例9: AddRange

 public override void AddRange(Array values)
 {
     this.inner.AddRange(values.Cast<MockDbParameter>());
 }
开发者ID:abeven,项目名称:MockDbProvider,代码行数:4,代码来源:MockDbParameterCollection.cs

示例10: CopyTo

 /// <summary>
 /// Copies the elements of the <see cref="T:System.Collections.ICollection"/> to an <see cref="T:System.Array"/>, starting at a particular <see cref="T:System.Array"/> index.
 /// </summary>
 /// <param name="array">The one-dimensional <see cref="T:System.Array"/> that is the destination of the elements copied from <see cref="T:System.Collections.ICollection"/>. The <see cref="T:System.Array"/> must have zero-based indexing. </param><param name="index">The zero-based index in <paramref name="array"/> at which copying begins. </param><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null. </exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is less than zero. </exception><exception cref="T:System.ArgumentException"><paramref name="array"/> is multidimensional.-or- The number of elements in the source <see cref="T:System.Collections.ICollection"/> is greater than the available space from <paramref name="index"/> to the end of the destination <paramref name="array"/>. </exception><exception cref="T:System.ArgumentException">The type of the source <see cref="T:System.Collections.ICollection"/> cannot be cast automatically to the type of the destination <paramref name="array"/>. </exception>
 public void CopyTo(Array array,
                    int index)
 {
     this.resultPropertyValueCollection.CopyTo(array.Cast<object>().ToArray(), index);
 }
开发者ID:YannBrulhart,项目名称:SystemWrapper-1,代码行数:9,代码来源:ResultPropertyValueCollectionWrap.cs

示例11: TranslateArray

 private static SObject TranslateArray(ScriptProcessor processor, Array array) =>
     processor.CreateArray(array.Cast<object>().Select((t, i) =>
             Translate(processor, array.GetValue(i))).ToArray());
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:3,代码来源:ScriptInAdapter.cs

示例12: UpdateResults

        public void UpdateResults(Array results) {
            results = results.Cast<object>().Take(50).ToArray();

            ResultView.ItemsSource = results;
            if (results.Length == 0) {
                ResultView.Visibility = Visibility.Collapsed;
                NoResults.Visibility = Visibility.Visible;
            } else {
                ResultView.Visibility = Visibility.Visible;
                NoResults.Visibility = Visibility.Collapsed;
            }
        }
开发者ID:Connorcpu,项目名称:EqBeats-WinRT,代码行数:12,代码来源:SearchResults.xaml.cs

示例13: ArraysEqual

 private static bool ArraysEqual(Array array1, Array array2)
 {
     if (array1.Length != array2.Length)
     {
         return false;
     }
     return !array1.Cast<object>().Where((t, i) => !AreEqual(array1.GetValue(i), array2.GetValue(i))).Any();
 }
开发者ID:guozanhua,项目名称:phmi,代码行数:8,代码来源:EditorHelper.cs

示例14: AddRange

        /// <summary>
        /// Adds an array of items with the specified values to the <see cref="T:System.Data.Common.DbParameterCollection"/>.
        /// </summary>
        /// <param name="values">An array of values of type <see cref="T:System.Data.Common.DbParameter"/> to add to the collection.
        ///                 </param><filterpriority>2</filterpriority>
        public override void AddRange(Array values)
        {
            if (values == null) throw new ArgumentNullException("values");

            InnerList.AddRange(values.Cast<TableStorageParameter>());
        }
开发者ID:yvesgoeleven,项目名称:NHibernate.Windows.Azure.Storage.Driver,代码行数:11,代码来源:TableStorageParameterCollection.cs

示例15: AddRange

		public override void AddRange(Array values)
		{
			this.AddRange(values.Cast<FbParameter>());
		}
开发者ID:cafee,项目名称:NETProvider,代码行数:4,代码来源:FbParameterCollection.cs


注:本文中的System.Array.Cast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。