简体   繁体   中英

how to merge codes in c# with passing parameters?

Is it possible to have this line

var newlist = listOrder.OrderBy(i => i.Date).ToList().GetRange(jtStartIndex, jtPageSize)

and this line of code together?

_repository.ReportRepository.GetTracks(jtStartIndex, jtPageSize, jtSorting);

I tried by adding an Operator but it doesn't work. ie like this:

var newlist = listOrder.OrderBy(i => i.Date).ToList().GetRange(jtStartIndex, jtPageSize) + _repository.ReportRepository.GetTracks(jtStartIndex, jtPageSize, jtSorting);

Full Controller Code:

[HttpPost]
        public JsonResult StudentList(string StartDate = "", string EndDate = "", int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null)
        {

            try
        {

            if (Request.IsAuthenticated == true)
            {
                string Path = @"C:\\5Newwithdate-1k.xls";
                OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source= '" + Path + "';Extended Properties=" + (char)34 + "Excel 8.0;IMEX=1;" + (char)34 + "");
                OleDbDataAdapter da = new OleDbDataAdapter("select * from [Sheet1$]", con);
                con.Close();
                System.Data.DataTable data = new System.Data.DataTable();
                da.Fill(data);

                List<TopPlayed> daa = new List<TopPlayed>();
                foreach (DataRow p in data.Rows)
                {
                    TopPlayed top = new TopPlayed()
                    {
                        TrackID = Convert.ToInt32(p.Field<double>("TrackID")),
                        Date = p.Field<DateTime>("DateTimes"),
                        TrackName = p.Field<string>("TrackName"),
                        ArtistName = p.Field<string>("ArtistName"),
                        Times = Convert.ToInt32(p.Field<double>("Times"))
                    };

                    daa.Add(top);
                }

                // var newlist = listOrder.OrderBy(i => i.Date).ToList().GetRange(jtStartIndex, jtPageSize) _repository.ReportRepository.GetTracks(jtStartIndex, jtPageSize, jtSorting);

                var newlist = _repository.ReportRepository.GetTracks(jtStartIndex, jtPageSize, jtSorting).OrderBy(i => i.Date).ToList().GetRange(jtStartIndex, jtPageSize);

                return Json(new { Result = "OK", Records = newlist, TotalRecordCount = daa.Count });

如果让我知道,我可能正在考虑您想做什么。

var newlist = _repository.ReportRepository.GetTracks(jtStartIndex, jtPageSize, jtSorting).OrderBy(i => i.Date).ToList().GetRange(jtStartIndex, jtPageSize);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM