当前位置:网站首页>ini怎么使用? C#教程
ini怎么使用? C#教程
2022-08-04 21:02:00 【cfqq1989】
在硬盘路径下保存数据。
结构体其中的一个值,或对象的某个属性值,保存在硬盘。
新建对象后,再把值一一赋值给对象。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.IO;
namespace Help
{
public class Help_Ini
{
#region API函数声明 (应用编程接口)
//using System.Runtime.InteropServices;
[DllImport("kernel32")]//返回0表示失败,非0为成功 (比如调用C++ 非托管类型的DLL)
private static extern long WritePrivateProfileString(string section, string key,
string val, string filePath);
[DllImport("kernel32")]//返回取得字符串缓冲区的长度
private static extern long GetPrivateProfileString(string section, string key,
string def, StringBuilder retVal, int size, string filePath);
#endregion
/// <summary>
/// get读
/// private string path = Application.StartupPath + "\\Config\\Port.ini";
/// 路径如"C:\\Users\\Administrator\\Desktop\\ScannerProj\\ScannerProj\\ScannerProj\\bin\\Debug\\Config\\Port.ini"
/// </summary>
/// <param name="Section">标签</param>
/// <param name="Key">属性</param>
/// <param name="NoText">值</param>
/// <param name="iniFilePath">硬盘路径</param>
/// <returns>string</returns>
public static string ReadIniData(string Section, string Key, string NoText, string iniFilePath)
{//using System.IO;
if (File.Exists(iniFilePath))
{
StringBuilder temp = new StringBuilder(1024);
GetPrivateProfileString(Section, Key, NoText, temp, 1024, iniFilePath);
return temp.ToString();
}
else
{
return string.Empty;
}
}
/// <summary>
/// set写
/// </summary>
/// <param name="Section">标签</param>
/// <param name="Key">属性</param>
/// <param name="Value">值</param>
/// <param name="iniFilePath">硬盘路径</param>
/// <returns>bool</returns>
public static bool WriteIniData(string Section, string Key, string Value, string iniFilePath)
{
if (File.Exists(iniFilePath))
{
return WritePrivateProfileString(Section, Key, Value, iniFilePath) != 0;
}
return false;
}
}
}
边栏推荐
- 路由中的meta、params传参的一些问题(可传不可传,为空,搭配,点击传递多次参数报错)
- Spss-系统聚类软件实操
- 88. (the home of cesium) cesium polymerization figure
- Using Baidu EasyDL to realize forest fire early warning and identification
- LayaBox---TypeScript---Example
- js数据类型、节流/防抖、点击事件委派优化、过渡动画
- [2022 Nioke Duo School 5 A Question Don't Starve] DP
- 实战:10 种实现延迟任务的方法,附代码!
- 密码学系列之:PEM和PKCS7,PKCS8,PKCS12
- DSPE-PEG-Aldehyde,DSPE-PEG-CHO,磷脂-聚乙二醇-醛基一种疏水18碳磷脂
猜你喜欢
![[2022 Hangzhou Electric Multi-School 5 1003 Slipper] Multiple Super Source Points + Shortest Path](/img/78/054329dec6a6faea5e9d583b6a8da5.png)
[2022 Hangzhou Electric Multi-School 5 1003 Slipper] Multiple Super Source Points + Shortest Path

DSPE-PEG-Aldehyde,DSPE-PEG-CHO,磷脂-聚乙二醇-醛基一种疏水18碳磷脂

buu web

STP基本配置及802.1D生成树协议的改进
![[Data Mining] Written Exam Questions for Sohu Data Mining Engineers](/img/d9/450eeecd5c7835d40ac38da41fc08e.png)
[Data Mining] Written Exam Questions for Sohu Data Mining Engineers

mdk5.14无法烧录

web漏洞扫描器-awvs

After encountering MapStruct, the conversion between PO, DTO and VO objects is no longer handwritten
![[2022 Hangzhou Electric Power Multi-School 5 1012 Questions Buy Figurines] Application of STL](/img/fe/1dd9418800366ee25067e154936e3b.png)
[2022 Hangzhou Electric Power Multi-School 5 1012 Questions Buy Figurines] Application of STL

SAP ABAP OData 服务如何支持 $select 有选择性地仅读取部分模型字段值试读版
随机推荐
如何最简单、通俗地理解爬虫的Scrapy框架?
链栈的应用
jekyll 在博客添加流程图
【2022杭电多校5 1012题 Buy Figurines】STL的运用
Spss-系统聚类手算实操
vim clear last search highlighting
Retrofit的使用及原理详解
3、IO流之字节流和字符流
【学术相关】清华教授发文劝退读博:我见过太多博士生精神崩溃、心态失衡、身体垮掉、一事无成!...
伺服电机矢量控制原理与仿真(1)控制系统的建立
matlab 画图
PowerCLi 导入License到vCenter 7
c语言小项目(三子棋游戏实现)
括号匹配
Oreo域名授权验证系统v1.0.6公益开源版本网站源码
dotnet compress Stream or file using lz4net
SAP ABAP OData 服务如何支持 $select 有选择性地仅读取部分模型字段值试读版
文章复现:超分辨率网络-VDSR
After encountering MapStruct, the conversion between PO, DTO and VO objects is no longer handwritten
知识分享|如何设计有效的帮助中心,不妨来看看以下几点