将它转换为dynamiv数组-it仅用于转换datetime的一个字符串,但我需要将动态数组字符串转换为日期时间 [英] converting it to the dynamiv array -it is for only one string converting datetime,but i need to convert dynamic array string to the date time
本文介绍了将它转换为dynamiv数组-it仅用于转换datetime的一个字符串,但我需要将动态数组字符串转换为日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
/* i need change this code t the array
in run time i enter only one datetime ,how to change this code to the dynamic array */
Console.WriteLine("please enter start date");
string Startdate = string.Empty;
Startdate = Console.ReadLine();
DateTime StartDate;
DateTime.TryParse(Startdate, out StartDate);
Console.Write(StartDate);
Console.ReadLine();
推荐答案
- 试试这个
--Try this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
DateTime StartDate;
int count = Convert.ToInt32(Console.ReadLine());
string Startdate = string.Empty;
List<string> list = new List<string>();
for (int i = 0; i <= count; i++)
{
Startdate = Console.ReadLine();
list.Add(Startdate);
}
foreach (string s in list)
{
DateTime.TryParse(s, out StartDate);
Console.Write(StartDate);
Console.ReadLine();
}
}
}
}
</string></string>
这篇关于将它转换为dynamiv数组-it仅用于转换datetime的一个字符串,但我需要将动态数组字符串转换为日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文