在IE#中将IEnumerable <string>转换为IEnumerable <int>

时间:2017-11-02 14:58:18

标签: c# .net visual-studio

我有:

IEnumerable<string> c = codigo_incidencia.Split('#');

我需要将“c”投射为IEnumerable<int>。我不知道如何在C#中进行演员表。

有人可以帮助我吗?

3 个答案:

答案 0 :(得分:4)

使用LINQ:

export class NotificationTotal extends React.Component {
    render() {
        return (
            <div>{amount goes here}</div>
        )
    }
}

答案 1 :(得分:4)

最简单的方法是同样使用linq <script> //Importing Line class from the vue-chartjs wrapper import { Line } from 'vue-chartjs' //Exporting this so it can be used in other components export default Line.extend({ data () { return { datacollection: { //Data to be represented on x-axis labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], datasets: [ { label: 'Data One', backgroundColor: '#f87979', pointBackgroundColor: 'white', borderWidth: 1, pointBorderColor: '#249EBF', //Data to be represented on y-axis data: [40, 20, 30, 50, 90, 10, 20, 40, 50, 70, 90, 100] } ] }, //Chart.js options that controls the appearance of the chart options: { scales: { yAxes: [{ ticks: { beginAtZero: true }, gridLines: { display: true } }], xAxes: [ { gridLines: { display: false } }] }, legend: { display: true }, responsive: true, maintainAspectRatio: false } } }, mounted () { //renderChart function renders the chart with the datacollection and options object. this.renderChart(this.datacollection, this.options) } }) </script>

.Select

如果您不确定这些部分是否有效,那么您需要使用var c = codigo_incidencia.Split('#').Select(int.Parse); ,如:Select parsed int, if string was parseable to int。如果使用C#7.0,您可以查看问题的this answer

TryParse

答案 2 :(得分:2)

如果字符串始终保证为数字,则可以这样做:

IEnumerable<int> c = codigo_incidencia.Split('#').Select(x => int.Parse(x));