C#如何为静态数组创建动力学函数 [英] C# how to create todynamic function for static arrays

查看:97
本文介绍了C#如何为静态数组创建动力学函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须为所有类型的静态数组创建ToDynamic()函数,它返回一个新的动态数组,该数组包含调用该函数的数组元素,就像这样`

I must create ToDynamic() function for all types of static arrays,which returns a new dynamic array consisting of the elements of the array from which the function was called, Like this`

int [] x = {1,2,3,4};




List<int> arr = x.ToDynamic();





我尝试过:



我是初学者,请帮帮我。

谢谢:)



What I have tried:

I'm a beginner,please help me.
Thanks :)

推荐答案

为什么?它已作为.NET的一部分存在...



因为数组实现IEnumerable< T>您可以对它们使用Linq方法:

Why? It already exists as part of .NET ...

Because arrays implement IEnumerable<T> you can use Linq methods on them:
int[] x = { 1, 2, 3, 4 };
List<int> arr = x.ToList();


这篇关于C#如何为静态数组创建动力学函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆