douyan6871 2014-05-29 11:02
浏览 53
已采纳

将PHP脚本转换为C#

I am currently stuck right now. I have moved to C# but one of the scripts in my PHP won't work when i convert it to C#. I have some problems with the array of minutes. Here is my PHP Script:

<?php
$start_hour = 10;
$end_hour = 22;
$minutes_array = array("15", "30", "45");
for($i=$start_hour; $i<($end_hour + 1); $i++){
    $string = $i . ':00';
    echo '<option value="' . $string . '">' . $string . '</option>';
    if($i != $end_hour){
        for($j=0; $j<sizeof($minutes_array); $j++){
            $string = $i . ':' . $minutes_array[$j];
             echo '<option value="' . $string . '">' . $string . '</option>';
        }
    }
}
?>

What it does is it outputs list items from 10 to 22 with 15, 30 and 45 between every count. So it looks like this

DropdownList
10:00
10:15
10:30
10:45
11:00
11:15
etc..

And here is my C# code so far:

int Opened = 8;
    int Closed = 22;

    for (int i = Opened; i < (Closed); i++)
    {
        string String = i + ":00";
        Response.Write(String);
        if (i != Closed)
        {
            for(int j = 0; j<sizeof(); j++)
            {
                String = i + ":" + 
            }
        }
    }

Can anyone help me converting this to C#? It would really make my day!

Thanks in advance, Jens

  • 写回答

4条回答 默认 最新

  • doudeng1870 2014-05-29 11:29
    关注
    var startHour = new DateTime(2000, 01, 01, 08, 00, 00);
    var endHour = new DateTime(2000, 01, 01, 22, 00, 00);
    var step = TimeSpan.FromMinutes(15);
    for (var time = startHour; time <= endHour; time += step)
    {
        Console.WriteLine(time.ToString("HH:mm"));
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建