首页 \ 问答 \ Process.Start,如果输入文件== 0 kb则不执行任何操作(Process.Start, do nothing if input file == 0 kb)

Process.Start,如果输入文件== 0 kb则不执行任何操作(Process.Start, do nothing if input file == 0 kb)

我有一个问题,我使用Process.Start来启动可执行文件,虽然可以说:如果input.txt == 0kb什么也不做,否则执行进程?

Process.Start("cmd.exe", @"/c test.exe -f input.txt > output.txt").WaitForExit();

I have a problem, I use Process.Start to launch an executable, although is it possible to say: if input.txt == 0kb do nothing, else execute process ?

Process.Start("cmd.exe", @"/c test.exe -f input.txt > output.txt").WaitForExit();

原文:https://stackoverflow.com/questions/6396661
更新时间:2023-06-07 15:06

最满意答案

您可以利用LINQ等C#功能,使其更简单:

        table.Source = new TableSource(
            JsonConvert.DeserializeObject<List<Field>> (response).
            Select (a => a.Value).
            ToArray ()
        );

当前代码的问题在于,如果Id不是索引和顺序,则会遇到异常。 如果要对项目进行排序,则可以轻松添加排序:

        table.Source = new TableSource(
            JsonConvert.DeserializeObject<List<Field>> (response).
            OrderBy(s => s.Id).
            Select (a => a.Value).
            ToArray ()

You could take advantage of the C# features like LINQ and make it a much simpler process:

        table.Source = new TableSource(
            JsonConvert.DeserializeObject<List<Field>> (response).
            Select (a => a.Value).
            ToArray ()
        );

The problem with your current code is that if the Id's are not 0 indexed and sequential you will run into an exception. If you want to sort the items then you can add sorting easily:

        table.Source = new TableSource(
            JsonConvert.DeserializeObject<List<Field>> (response).
            OrderBy(s => s.Id).
            Select (a => a.Value).
            ToArray ()

相关问答

更多
  • 该任务是异步的,因此当您加载数组时,您必须重新加载表 func getJSON() { let url = NSURL(string: baseURL) let request = NSURLRequest(URL: url!) let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration()) let task = session.dataTa ...
  • 看起来像json [“task_name”]不是一个数组而不是第一级,而是task数组中对象的属性,这就是为什么你得到一个空数组。 如果您打算在tableview中显示tak,则应该执行此类操作 if let data = json["tasks"].arrayValue as [JSON]?{ Seems like json["task_name"] is not an array and isn't at first level, instead is a property of the object ...
  • 您必须将Company中的employees声明为阵列 var employees = [Employee]() 以及初始化程序 init(name ... , employees: [Employee]) { 并且 - 非常非常重要 -您必须在repeat循环中创建Employee实例,否则您将employees.count乘以相同的对象(由于类的引用语义) ... for employeesDict in employees { if let name = employe ...
  • 这是因为在viewDidLoad您将numberOfCells设置为> 0但是在eventscd没有任何eventscd 。 这就是为什么当尝试从eventscd读取值时,会得到索引超出范围的错误。 理想情况下,返回的行数应为eventscd.count , eventscd应在加载表内容之前填充eventscd (或者在获取数据并向eventscd添加值后重新加载表) This is because in the viewDidLoad you are setting the numberOfCells ...
  • 在视图控制器外部创建一个自定义类Person class Person { var firstName = "" var lastName = "" var title = "" var party = "" } 在视图控制器中创建一个Person数组 var people = [Person]() JSON有一个包含字典数组的关键results 。 在viewDidLoad解析JSON并创建Person实例。 最后重新加载表格视图。 override func viewDidLoad( ...
  • 您可以利用LINQ等C#功能,使其更简单: table.Source = new TableSource( JsonConvert.DeserializeObject> (response). Select (a => a.Value). ToArray () ); 当前代码的问题在于,如果Id不是索引和顺序,则会遇到异常。 如果要对项目进行排序,则可以轻松添加排序: ...
  • 您正在设置数据,如下所示: [_tableData insertObject:title atIndex:0]; [_tableData insertObject:release_year atIndex:1]; [_tableData insertObject:themoviedb atIndex:2]; [_tableData insertObject:original_title atIndex:3]; 但是你正在读出如下数据: ...
  • 您可以使用中间自定义结构。 将JSON解析为自定义结构。 使用此结构作为表视图的模型。 当用户点击行映射结构实例到NSManagedObject并保存它。 You could use an intermediate custom struct. Parse the JSON into a custom struct. Use this struct as model for the table view. When the user taps a row map the struct instance to ...
  • 尝试使用基于块的NSURLConnection。 我想你形成webdata的方式就是问题。 NSURL *url = [NSURL URLWithString:@"http://url.json"]; NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; [NSURLConnection sendAsynchronousRequest:urlRequest queue: ...
  • 您没有实例化tableView委托。 确保在viewDidLoad()调用self.weatherTableView.delegate = self 。 此外,每次加载数据时都应创建一个新的arrDict。 self.arrDict = [] 。 如果上述调整不起作用,您应该花些时间调试它。 确保第二个请求正在加载数据,如果是,则可能不会调用self.weatherTableView.reloadData() 。 您可以尝试将其移动到loadDataWeather() 。 You are not insta ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)