首页 \ 问答 \ C#在应用程序中保存文件位置(C# Saving file location within application)

C#在应用程序中保存文件位置(C# Saving file location within application)

我希望用户能够选择程序文件在其PC中的位置,并在每次启动应用程序时保存该位置,直到他们更改它为止。 我从来没有用C#做过这样的事情,我仍然认为自己是C#的新手。 我已经考虑过创建一个Settings.txt文件或XML文件并读取用户保存的行,但我仍然不确定如何存储它。 任何帮助或建议将不胜感激。


I'm wanting the user to be able to choose the location of where a program file is located within their PC and save that location for every time my application is launched until they change it. I have never done anything like this with C#, I still consider myself a novice with C#. I've considered making a Settings.txt file or XML file and reading the lines as saved by the user, yet I still am unsure as how to store this. Any help or suggestions would be greatly appreciated.


原文:https://stackoverflow.com/questions/12735723
更新时间:2020-12-15 18:12

最满意答案

我看起来像一个错误,我设法用更简单的代码重现这个问题:

fn main() {
    let mut vector = vec!(1u, 2u);
    for &x in vector.iter() {
        let cap = vector.capacity();
        println!("Capacity was: {}", cap);
        vector.grow(cap, &0u); // be sure to cause reallocation
        *vector.get_mut(1u) = 5u;
        println!("Value: {}", x);
    }
}

它输出:

Capacity was: 4
Value: 1
Capacity was: 8
Value: 2

我正在修改向量内容并重新分配,导致底层切片引用未分配的内存( vector.iter()实际上是vector.as_slice().iter() )。

它看起来像是最近的变化,由于双重借用而无法在生锈0.11上编译。

我在这里打开了一个问题: https//github.com/rust-lang/rust/issues/16820

编辑(2014年9月10日):该错误现已更正: https//github.com/rust-lang/rust/pull/17101


I looks like a bug, I managed to reproduce this issue with simpler code :

fn main() {
    let mut vector = vec!(1u, 2u);
    for &x in vector.iter() {
        let cap = vector.capacity();
        println!("Capacity was: {}", cap);
        vector.grow(cap, &0u); // be sure to cause reallocation
        *vector.get_mut(1u) = 5u;
        println!("Value: {}", x);
    }
}

It outputs :

Capacity was: 4
Value: 1
Capacity was: 8
Value: 2

I'm modifying the vector content and reallocating, causing the underlying slice to refer to unallocated memory (vector.iter() is in fact vector.as_slice().iter()).

It looks like a recent change, it doesn't compile on rust 0.11 due to double borrow.

I opened an issue here : https://github.com/rust-lang/rust/issues/16820

Edit (10 sept 2014) : The bug is now corrected : https://github.com/rust-lang/rust/pull/17101

相关问答

更多
  • 你正在与一生的问题发生冲突。 您的计划中有多个不同的生命周期: type Object<'a> = BTreeMap<&'a str, i32>; =>这是一个 &'a mut Object<'a> =>这里最多有两个 struct Sub<'a>(&'a mut Object<'a>, &'a str); =>这里有三个 显然,没有理由引用Object<'a> &str BTreeMap的&str具有相同的生命周期。 但是,你告诉编译器你希望两个生命周期都是一样的! 当你写: struct Sub<'a> ...
  • 问题来自于read_event原型中的'b life : pub fn read_event<'a, 'b>( &'a mut self, buf: &'b mut Vec ) -> Result> 这会将缓冲区的生命周期与返回值的生命周期相关联,因此只要结果处于活动状态,就无法重新使用缓冲区。 当你不想在完成结果使用后不想递归和递归时,你可以通过提早返回来解决它: pub fn read_next(&mut self) -> Result
  • 你有两个问题: 无法移出借用的上下文:请参阅借用通用类型以获取解释时无法移出借用内容 。 无法分配给不可变字段:您只有一个&Node ; 修改Node你需要一个&mut Node 。 在模式中使用mut curr只会使绑定变为可变,这意味着您可以为curr分配一个新值。 但是,您不能修改curr所指的内容。 在整个代码中传播& to &mut转换,它会起作用。 You have two problems: Cannot move out of borrowed context: see Cann ...
  • 这实际上就是终身注释的意义。 如果你有一个具有这个原型的功能: fn get_bar<'a>(&'a Foo) -> Bar<'a> { ... } 这意味着返回的Bar对象拥有一个与Foo对象相关的生命周期。 作为结果: 只要它存活, Bar对象就会借用Foo对象 Bar对象不允许超过Foo对象。 在您的情况下, connection的类型为PooledConnection<'a, ...> ,其中'a是在&'a mut req中定义的生命周期,因此它被视为req的可变借用。 它在重构之前工作,因为co ...
  • 问题是你不小心将Global的通用生命周期参数与可变借用的生命周期联系在一起。 当你需要&'a mut Global<'a> ,这意味着Global的可变借用的持续时间必须与引用的时间一样长,即Global存在的全长。 因此,当你编写&mut global时,你已经推断出对global的永久借用。 我会用这种方式用不完全有效的语法编写它,但要明白这一点: fn main() { 'a: { let number: i32 + 'a = 2; let mut globa ...
  • 由于迭代器在我的用例中对缓冲区进行了引用,因此它们不能实现stdlib中的Iterator特性,而是通过next_ref函数使用,该函数与Iterator::next相同,但需要额外的生命周期参数。 您正在描述一个流式迭代器 。 有一个箱子,适合称为streaming_iterator 。 文档描述你的问题(重点是我的): 虽然标准Iterator特性的功能基于next方法,但StreamingIterator的功能基于一对方法: advance和get 。 这基本上将next逻辑分开(实际上, Strea ...
  • 你有两个选择。 1)每晚使用并将#![feature(nll)]放在文件的顶部。 非词汇生命周期正好解决了这个问题:即使s1借用不用于else块,它仍然存在并阻止self.v变异。 在非词汇生命周期中,编译器会认识到s1实际上已经死了,让你再次借用。 2)像这样构造你的代码: fn add1(&mut self, n: u32) { { // add a scope around s1 so that it disappears later let s1 = self.v.last_ ...
  • 这是第一种方法的变体,使用递归来避免借用冲突。 迭代等价物无法编译,因为在处理可变值的可变借用指针时,Rust过于严格。 impl Node { fn traverse_path<'p>(&mut self, mut path: &'p [Id]) -> (&mut Node, &'p [Id]) { // ' if self.children.contains_key(&path[0]) { self.children[path[0]].traverse_p ...
  • 我看起来像一个错误,我设法用更简单的代码重现这个问题: fn main() { let mut vector = vec!(1u, 2u); for &x in vector.iter() { let cap = vector.capacity(); println!("Capacity was: {}", cap); vector.grow(cap, &0u); // be sure to cause reallocation ...
  • 一个可变参考可以永远借用,但这不是这里发生的事情。 使用&形成参考时,需要明确可变性; 除非你指定&mut它将是一个不可变的引用。 你的例子可以简化为: use std::ascii::AsciiExt; fn main() { let mut t = "s".to_string(); let u = &mut t; u.make_ascii_uppercase(); let v = &*u; let () = v; } 最后一行是让编译器告诉我们(在错误消息中 ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)