C#各种配置文件使用,操作方法总结

2023-05-16

配置文件操作

    配置文件一般分为内置配置文和用户自定义配置文件。

    内置配置文件包括app.config、web.config、Settings.settings等等。

用户自定义配置文件一般是将配置信息放到XML文件或注册表中,配置信息一般包括程序设置,记录运行信息,保存控件的信息(比如位置,样式)。

一、内置配置文件操作

app.config和web.config操作类似,以app.config为例,Settings.settings能够指定值的类型和范围。

1.app.config文件操作

该配置文件中主要的节点有:connectionStrings、appSettings、configSections等,这几个属于常用,操作都略有不同,DotNet提供直接操作各个节点的方法。在用到ConfigurationManager时要添加system.configuration.dll程序集的引用。

程序移植后配置文件的修改会保存在.exe.config的文件中,但是根据我经验如果你不修改配置文件,一般exe不自动创建一个.exe.config的文件。

在项目进行编译后,在bin\Debuge文件下,将出现两个配置文件,一个名为“*.EXE.config”,另一个名为“*.vshost.exe.config”。第一个文件为项目实际使用的配置文件,在程序运行中所做的更改都将被保存于此;第二个文件为原代码“app.config”的同步文件,在程序运行中不会发生更改。

 

connectionStrings:由于保存数据连接字符串。

读:

[csharp] view plain copy print ?
  1. ConfigurationManager.ConnectionStrings["AccessDB"].ConnectionString;  
ConfigurationManager.ConnectionStrings["AccessDB"].ConnectionString;

写:

[csharp] view plain copy print ?
  1. //设置连接字符串  
  2.   
  3. ConnectionStringSettings setConnStr = newConnectionStringSettings("AccessDB", connectionString,"System.Data.OleDb");  
  4.   
  5. //打开当前应用程序的app.config文件,进行操作  
  6.   
  7. Configuration appConfig =ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);  
  8.   
  9. //由于没有更新连接字符串的方法,所以这里直接再添加一个连接字符串  
  10.   
  11. appConfig.ConnectionStrings.ConnectionStrings.Add(setConnStr);  
  12.   
  13. appConfig.Save();  
  14.   
  15. // 强制重新载入配置文件的ConnectionStrings配置节  
  16.   
  17. ConfigurationManager.RefreshSection("connectionStrings");  
//设置连接字符串

ConnectionStringSettings setConnStr = newConnectionStringSettings("AccessDB", connectionString,"System.Data.OleDb");

//打开当前应用程序的app.config文件,进行操作

Configuration appConfig =ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

//由于没有更新连接字符串的方法,所以这里直接再添加一个连接字符串

appConfig.ConnectionStrings.ConnectionStrings.Add(setConnStr);

appConfig.Save();

// 强制重新载入配置文件的ConnectionStrings配置节

ConfigurationManager.RefreshSection("connectionStrings");

appSettings:主要存储程序设置,以键值对的形式出现。

读:

[csharp] view plain copy print ?
  1. String str = ConfigurationManager.AppSettings["DemoKey"];  
String str = ConfigurationManager.AppSettings["DemoKey"];

写:

[csharp] view plain copy print ?
  1. Configuration cfg=ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);  
  2.   
  3. cfg.AppSettings.Settings["DemoKey"].Value= "DemoValue";  
  4.   
  5. cfg.Save();  
Configuration cfg=ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

cfg.AppSettings.Settings["DemoKey"].Value= "DemoValue";

cfg.Save();

configSections:自定义配置节

name:自定义配置节的名称。

type:自定义配置节的类型,主要包括:

System.Configuration.SingleTagSectionHandler

System.Configuration.DictionarySectionHandler

System.Configuration.NameValueSectionHandler。

不同的type不但设置配置节的方式不一样,最后访问配置文件的操作上也有差异。

三个不同的type操作:

[html] view plain copy print ?
  1. <?xmlversionxmlversion="1.0" encoding="utf-8" ?>  
  2.   
  3. <configuration>  
  4.   
  5.      <configSections>  
  6.   
  7.          <sectiontypesectiontype="System.Configuration.SingleTagSectionHandler"/>  
  8.   
  9.          <sectiontypesectiontype="System.Configuration.DictionarySectionHandler"/>  
  10.   
  11.          <sectiontypesectiontype="System.Configuration.NameValueSectionHandler" />  
  12.   
  13.      </configSections>  
  14.   
  15.      <Test1 setting1="Hello"setting2="World"/>  
  16.   
  17.      <Test2>  
  18.   
  19.          <add key="Hello"value="World" />  
  20.   
  21.      </Test2>  
  22.   
  23.      <Test3>  
  24.   
  25.          <add key="Hello"value="World" />  
  26.   
  27.      </Test3>     
  28.   
  29. </configuration>  
<?xmlversion="1.0" encoding="utf-8" ?>

<configuration>

     <configSections>

         <sectiontype="System.Configuration.SingleTagSectionHandler"/>

         <sectiontype="System.Configuration.DictionarySectionHandler"/>

         <sectiontype="System.Configuration.NameValueSectionHandler" />

     </configSections>

     <Test1 setting1="Hello"setting2="World"/>

     <Test2>

         <add key="Hello"value="World" />

     </Test2>

     <Test3>

         <add key="Hello"value="World" />

     </Test3>   

</configuration>


 

说明:在声明部分使用<sectiontype="System.Configuration.SingleTagSectionHandler"/>声明了一个配置节它的名字叫Test1,类型为SingleTagSectionHandler。在设置配置节部分使用 <Test1 setting1="Hello"setting2="World"/>设置了一个配置节,它的第一个设置的值是Hello,第二个值是World,当然还可以有更多。其它的两个配置节和这个类似。 

下面我们看在程序中如何访问这些自定义的配置节。我们用过ConfigurationSettings类的静态方法GetConfig来获取自定义配置节的信息。

[csharp] view plain copy print ?
  1. //访问配置节Test1  
  2.   
  3. IDictionary IDTest1 =(IDictionary)ConfigurationSettings.GetConfig("Test1");  
  4.   
  5. string str = (string)IDTest1["setting1"]+" "+(string)IDTest1["setting2"];  
  6.   
  7. MessageBox.Show(str);        //输出Hello World  
  8.   
  9. //访问配置节Test1的方法2  
  10.   
  11. string[] values1=new string[IDTest1.Count];  
  12.   
  13. IDTest1.Values.CopyTo(values1,0);  
  14.   
  15. MessageBox.Show(values1[0]+""+values1[1]);     //输出HelloWorld  
  16.   
  17. //访问配置节Test2  
  18.   
  19. IDictionary IDTest2 =(IDictionary)ConfigurationSettings.GetConfig("Test2");  
  20.   
  21. string[] keys=new string[IDTest2.Keys.Count];  
  22.   
  23. string[] values=new string[IDTest2.Keys.Count];  
  24.   
  25. IDTest2.Keys.CopyTo(keys,0);  
  26.   
  27. IDTest2.Values.CopyTo(values,0);  
  28.   
  29. MessageBox.Show(keys[0]+" "+values[0]);  
  30.   
  31. //访问配置节Test3  
  32.   
  33. NameValueCollectionnc=(NameValueCollection)ConfigurationSettings.GetConfig("Test3");  
  34.   
  35. MessageBox.Show(nc.AllKeys[0].ToString()+""+nc["Hello"]); //输出HelloWorld  
//访问配置节Test1

IDictionary IDTest1 =(IDictionary)ConfigurationSettings.GetConfig("Test1");

string str = (string)IDTest1["setting1"]+" "+(string)IDTest1["setting2"];

MessageBox.Show(str);        //输出Hello World

//访问配置节Test1的方法2

string[] values1=new string[IDTest1.Count];

IDTest1.Values.CopyTo(values1,0);

MessageBox.Show(values1[0]+""+values1[1]);     //输出HelloWorld

//访问配置节Test2

IDictionary IDTest2 =(IDictionary)ConfigurationSettings.GetConfig("Test2");

string[] keys=new string[IDTest2.Keys.Count];

string[] values=new string[IDTest2.Keys.Count];

IDTest2.Keys.CopyTo(keys,0);

IDTest2.Values.CopyTo(values,0);

MessageBox.Show(keys[0]+" "+values[0]);

//访问配置节Test3

NameValueCollectionnc=(NameValueCollection)ConfigurationSettings.GetConfig("Test3");

MessageBox.Show(nc.AllKeys[0].ToString()+""+nc["Hello"]); //输出HelloWorld

配置节处理程序

返回类型

SingleTagSectionHandler

Systems.Collections.IDictionary

DictionarySectionHandler

Systems.Collections.IDictionary

NameValueSectionHandler

Systems.Collections.Specialized.NameValueCollection

 

sectionGroup:自定义配置节组

配置节组是使用<sectionGroup>元素,将类似的配置节分到同一个组中。配置节组声明部分将创建配置节的

包含元素,在<configSections>元素中声明配置节组,并将属于该组的节置于<sectionGroup>元素中。下面

是一个包含配置节组的配置文件的例子:

[html] view plain copy print ?
  1. <?xml version="1.0"encoding="utf-8" ?>  
  2.   
  3. <configuration>  
  4.   
  5.      <configSections>  
  6.   
  7.         <sectionGroup >  
  8.   
  9.             <section type="System.Configuration.NameValueSectionHandler"/>  
  10.   
  11.         </sectionGroup>  
  12.   
  13.      </configSections>  
  14.   
  15.     
  16.   
  17.      <TestGroup>  
  18.   
  19.         <Test>  
  20.   
  21.             <add key="Hello" value="World"/>  
  22.   
  23.         </Test>  
  24.   
  25.      </TestGroup>  
  26.   
  27. </configuration>  
<?xml version="1.0"encoding="utf-8" ?>

<configuration>

     <configSections>

        <sectionGroup >

            <section type="System.Configuration.NameValueSectionHandler"/>

        </sectionGroup>

     </configSections>

  

     <TestGroup>

        <Test>

            <add key="Hello" value="World"/>

        </Test>

     </TestGroup>

</configuration>


下面是访问这个配置节组的代码:

NameValueCollectionnc=(NameValueCollection)ConfigurationSettings.GetConfig("TestGroup/Test");

MessageBox.Show(nc.AllKeys[0].ToString()+""+nc["Hello"]);    //输出HelloWorld

 

2.Settings.settings配置文件操作

 这个用的不多,操作也很简单,在此不详细叙述。

 

二、用户自定义文件操作

1.XML配置文件操作

XML配置文件一般由我们自己定义格式,由于某些地方对于app.config不提供写的功能,我们就需要自己来操作这个XML,这里我们就拿它作为例子,来说明XML的操作。

privatevoid SaveConfig(string ConnenctionString)
        
{
             XmlDocument doc=new XmlDocument();
            
//获得配置文件的全路径
             stringstrFileName=AppDomain.CurrentDomain.BaseDirectory.ToString()+"Code.exe.config";
            
doc.LOAd(strFileName);
             //找出名称为“add”的所有元素
            XmlNodeList nodes=doc.GetElementsByTagName("add");
            
for(int i=0;i<nodes.Count;i++)
            
{
                 //获得将当前元素的key属性
                 XmlAttributeatt=nodes[i].Attributes["key"];
                
//根据元素的第一个属性来判断当前的元素是不是目标元素
                 if (att.Value=="ConnectionString")
                
{
                     //对目标元素中的第二个属性赋值
                    att=nodes[i].Attributes["value"];
                    
att.Value=ConnenctionString;
                     break;
                
}
             }
             //保存上面的修改
            doc.Save(strFileName);
         }

 

2.注册表配置操作

首先注册表也是以键值对的形式存储的,DotNet提供对注册表的操作。

操作实例:

      

[csharp] view plain copy print ?
  1.   <span style="font-size:12px;">/// <summary>  
  2.  /// 从注册表中加载窗体位置大小等信息  
  3.  /// </summary>  
  4.  public static voidLoadFormPosition(System.Windows.Forms.Form Fo)  
  5.  {  
  6.      Microsoft.Win32.RegistryKey rk =Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\\\MapWinGISConfig",false);  
  7.      try  
  8.      {  
  9.          if ((rk.GetValue(Fo.Name +"_x").ToString() != "") && (rk.GetValue(Fo.Name +"_y").ToString()!= "") && (rk.GetValue(Fo.Name + "_w").ToString()!= "") && (rk.GetValue(Fo.Name+ "_h").ToString() != ""))  
  10.          {  
  11.              Fo.Location = newSystem.Drawing.Point(int.Parse(rk.GetValue(Fo.Name +"_x").ToString(),CultureInfo.InvariantCulture), int.Parse(rk.GetValue(Fo.Name +"_y").ToString(),CultureInfo.InvariantCulture));  
  12.   
  13.              Fo.Size = newSystem.Drawing.Size(int.Parse(rk.GetValue(Fo.Name +"_w").ToString(),CultureInfo.InvariantCulture), int.Parse(rk.GetValue(Fo.Name +"_h").ToString(),CultureInfo.InvariantCulture));  
  14.          }  
  15.      }  
  16.      catch  
  17.      {  
  18.      }  
  19.      finally  
  20.      {  
  21.          rk.Close();  
  22.      }  
  23.  }  
  24.  /// <summary>  
  25.  /// 将窗体位置大小信息保存在注册表中  
  26. /// </summary>  
  27.  public static voidSaveFormPosition(System.Windows.Forms.Form Fo)  
  28.  {  
  29.      Microsoft.Win32.RegistryKey rk =Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\\\\MapWinGISConfig");  
  30.   
  31.      if (Fo.Visible &&Fo.WindowState != System.Windows.Forms.FormWindowState.Minimized&&Fo.Location.X > -1 && Fo.Location.Y > -1 && Fo.Size.Width> 1 && Fo.Size.Height > 1)  
  32.      {  
  33.          rk.SetValue(Fo.Name +"_x", Fo.Location.X);  
  34.          rk.SetValue(Fo.Name +"_y", Fo.Location.Y);  
  35.          rk.SetValue(Fo.Name +"_w", Fo.Size.Width);  
  36.          rk.SetValue(Fo.Name +"_h", Fo.Size.Height);  
  37.      }  
  38.      rk.Close();  
  39.  }</span>  
         <span style="font-size:12px;">/// <summary>
        /// 从注册表中加载窗体位置大小等信息
        /// </summary>
        public static voidLoadFormPosition(System.Windows.Forms.Form Fo)
        {
            Microsoft.Win32.RegistryKey rk =Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\\\MapWinGISConfig",false);
            try
            {
                if ((rk.GetValue(Fo.Name +"_x").ToString() != "") && (rk.GetValue(Fo.Name +"_y").ToString()!= "") && (rk.GetValue(Fo.Name + "_w").ToString()!= "") && (rk.GetValue(Fo.Name+ "_h").ToString() != ""))
                {
                    Fo.Location = newSystem.Drawing.Point(int.Parse(rk.GetValue(Fo.Name +"_x").ToString(),CultureInfo.InvariantCulture), int.Parse(rk.GetValue(Fo.Name +"_y").ToString(),CultureInfo.InvariantCulture));

                    Fo.Size = newSystem.Drawing.Size(int.Parse(rk.GetValue(Fo.Name +"_w").ToString(),CultureInfo.InvariantCulture), int.Parse(rk.GetValue(Fo.Name +"_h").ToString(),CultureInfo.InvariantCulture));
                }
            }
            catch
            {
            }
            finally
            {
                rk.Close();
            }
        }
        /// <summary>
        /// 将窗体位置大小信息保存在注册表中
       /// </summary>
        public static voidSaveFormPosition(System.Windows.Forms.Form Fo)
        {
            Microsoft.Win32.RegistryKey rk =Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\\\\MapWinGISConfig");

            if (Fo.Visible &&Fo.WindowState != System.Windows.Forms.FormWindowState.Minimized&&Fo.Location.X > -1 && Fo.Location.Y > -1 && Fo.Size.Width> 1 && Fo.Size.Height > 1)
            {
                rk.SetValue(Fo.Name +"_x", Fo.Location.X);
                rk.SetValue(Fo.Name +"_y", Fo.Location.Y);
                rk.SetValue(Fo.Name +"_w", Fo.Size.Width);
                rk.SetValue(Fo.Name +"_h", Fo.Size.Height);
            }
            rk.Close();
        }</span>

三、应用程序信息配置

通过代码继承ApplicationSettingsBase类(C/S模式),在代码中设置相关的属性。

   1.继承该类一般有类属性[SettingsProvider("System.Configuration.LocalFileSettingsProvider")]-详情如下

   2.每个属性必须设置是[ApplicationScopedSetting()]还是[UserSocpedSetting()],还可以设置默认值[DefaultSettingValueAttribute("100,100")]

   3.属性设置完成后,在方法级别或方法内部(视情况而定)实例化该继承的类,在窗体加载时设置相应属性。加载程序配置方法有两种-详情如下。

   4.如果需要可以利用事件监视设置的属性改变、保存、加载时进行哪些操作

   5.在窗体注销时保存设置。

详解:

 (一),LocalFileSettingsProvider---为应用程序设置类提供持久性存储。

     1.该类提供一种机制--程序使用配置数据的机制,其将程序的设置文件保存到默认的位置。

     2.客户端并不显示访问这个类,而是在需要服务时由设置机制自动调用,如:ApplicationSettingsBase中的很多成员都使用该类。

     3.该类将配置文件保存为.config的XML文件

         1.若字段的属性设置为[UserScopedSetting()],则保存为user.config文件,

           保存位置C:\Documentsand Settings\[计算机用户名]\LocalSettings\Application Data\[AssemblyCompany("huzongzhe")程序集中的一个属性]\

         2.若字段的属性设置为[ApplicationScopedSetting()],则保存为[程序名].exe.config文件,

           保存位置:与可执行文件相同的目录中。

    4.ToolStripManager.LoadSettings(this)和ToolStripManager.SaveSettings(this)方法解释

       首先,ToolStripManager提供Toolstrip相关类型的一些操作,包括合并,拆分toolstrip、呈现样式、保存加载设置。

       其次,LoadSettings、SaveSettings的位置是C:\Documentsand Settings\[计算机用户名]\LocalSettings\Application Data\[AssemblyCompany("huzongzhe")程序集中的一个属性]\

             与LocalFileSettingsProvider提供的文件配置是同一个位置,并且是同一个文件。  

      最后,LoadSettings的内容:Size、IsDefault、ItemOrder、Visible、ToolStripPanelName、Name、Location等7个属性。

 

 

 (二),加载程序配置方法

     1.通过函数Binding来绑定,这样在程序加载时直接与配置文件的数据绑定,并且可以在值改变时直接加载到XML中。

           Binding bndBackColor = new Binding("BackColor", frmSettings1,

               "FormBackColor", true,DataSourceUpdateMode.OnPropertyChanged);

           this.DataBindings.Add(bndBackColor);

 

     2.通过提取的方法。这样每次修改后不能动态改变,需要手动设置。

      this.Size = frmSettings1.FormSize;

 (三),[SettingsGroupName("System.Windows.Forms.ToolStripSettings.MapWinGIS.MainProgram.MapWinForm")]类属性

     设置每个Toolstrip的前缀名,即每个组的前面限定名

     例如:tlbZoom工具条在配置文件中的标识-->System.Windows.Forms.ToolStripSettings.MapWinGIS.MainProgram.MapWinForm.tlbZoom

 

 (四),方法Reload();Reset();Save(); Upgrade();

       Reload()方法从配置文件重新加载值。

      Reset() 方法将设置重置为默认值。

       Save() 方法保存当前设置的值。

      Upgrade()更新程序设置值。

 

代码示例:

[csharp] view plain copy print ?
  1. [SettingsProvider("System.Configuration.LocalFileSettingsProvider")]  
  2. [SettingsGroupName("System.Windows.Forms.ToolStripSettings.MapWinGIS.MainProgram.MapWinForm")]  
  3.    sealedclass ToolStripSettings : ApplicationSettingsBase  
  4.    {  
  5.       public ToolStripSettings(string settingsKey) : base(settingsKey)//传过来的是toolstrip的Name属性  
  6.        {  
  7.        }  
  8.   
  9.       [UserScopedSetting()]  
  10.       public System.Drawing.Point Location  
  11.        {  
  12.           get  
  13.            {  
  14.               if (this["Location"] == null)  
  15.                {  
  16.                   if (this.GetPreviousVersion("Location") == null)  
  17.                   {  
  18.                        return newSystem.Drawing.Point(-1, -1);  
  19.                   }  
  20.                   return ((System.Drawing.Point)(this.GetPreviousVersion("Location")));  
  21.               }  
  22.               return ((System.Drawing.Point)(this["Location"]));  
  23.            }  
  24.   
  25.          set  
  26.            {  
  27.               this["Location"] = value;  
  28.            }  
  29.        }  
  30.   
  31.       [UserScopedSetting(), DefaultSettingValue("StripDocker.Top")]  
  32.       public string ToolStripPanelName  
  33.        {  
  34.           get  
  35.            {  
  36.               if(string.IsNullOrEmpty((string)(this["ToolStripPanelName"])))  
  37.               {  
  38.                   // 设置早期设置的值  
  39.                    if(string.IsNullOrEmpty((string)(this.GetPreviousVersion("ToolStripPanelName"))))  
  40.                   {  
  41.                       // 默认值  
  42.                       return string.Empty;  
  43.                   }  
  44.                   return ((string)(this.GetPreviousVersion("ToolStripPanelName")));  
  45.               }  
  46.               return ((string)(this["ToolStripPanelName"]));  
  47.            }  
  48.          set  
  49.            {  
  50.               this["ToolStripPanelName"] = value;  
  51.            }  
  52.        }  
  53.   
  54.       [UserScopedSetting()]  
  55.       [DefaultSettingValue("ImageAndText")]  
  56.       public string DisplayStyle  
  57.        {  
  58.           get  
  59.            {  
  60.               const string defaultValue = "ImageAndText";  
  61.               if (this["DisplayStyle"] == null ||((string)(this["DisplayStyle"])) ==string.Empty)  
  62.             {  
  63.                   // 设置早期值  
  64.                   if (this.GetPreviousVersion("DisplayStyle") == null ||((string)(this.GetPreviousVersion("DisplayStyle")))== string.Empty)  
  65.                    {  
  66.                        // 默认值  
  67.                        return defaultValue;  
  68.                   }  
  69.                   return ((string)(this.GetPreviousVersion("DisplayStyle")));  
  70.               }  
  71.               return ((string)(this["DisplayStyle"]));  
  72.            }  
  73.           set  
  74.            {  
  75.               this["DisplayStyle"] = value;  
  76.            }  
  77.        }  
  78.    } 
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

C#各种配置文件使用,操作方法总结 的相关文章

  • 动态存储和静态存储区域区别

    动态存储方式 所谓动态存储方式是指在程序运行期间根据需要进行动态的分配存储空间的方式 动态存储变量是在程序执行过程中 xff0c 使用它时才分配存储单元 xff0c 使用完毕立即释放 典型的例子是函数的形式参数 xff0c 在函数定义时并不
  • c++中默认32位int类型转换截取高位部分

    int类型的变量固定为4个字节 xff0c 共32位 int类型变量初始值一般为0 xff0c 范围 2 31 2 31 1 即 2147483648 xff0c 2147483647 16 位系统下 xff0c int 是 2 个字节 x
  • c#-接口

    c 中的接口中必须是未实现的方法 xff0c 例如属性 xff0c 事件 xff0c 索引器 xff0c 一般函数等 除此之外不能有其他的成员 xff0c 类可以继承两个或两个以上的接口 xff0c 派生类中必须实现接口中的所有方法
  • C# SerialPort 读写三菱FX系列PLC

    1 xff1a 串口初始化 com 61 new SerialPort 34 COM3 34 9600 Parity Even 7 StopBits One 2 xff1a 打开关闭串口 if com IsOpen com Close co
  • c++中用new和不用new创建对象的本质区别

    1 xff1a 作用域不同 不用new xff1a 作用域限制在定义类对象的方法中 xff0c 当方法结束时 xff0c 类对象也被系统释放了 xff0c xff08 安全不会造成内存系统泄漏 xff09 用new xff1a 创建的是指向
  • ubuntu系统通过ifconfig查看eth0只有ipv6没有ipv4的解决方案

    只有inet6 addr 配置eth0 3 重新启动sudo etc init d networking restart IP地址出来了 看起来就正常 4 看其他资料 xff0c linux 43 QT4 0 xff0c 在这个开发板上的l
  • Action<T> 无参数委托详解

    C 委托Action Action lt T gt Func lt T gt Predicate lt T gt CLR环境中给我们内置了几个常用委托Action Action lt T gt Func lt T gt Predicate
  • 在C++里,有两种方法创建对象:

    方法一 xff1a ClassName object param 这样就声明了一个ClassName类型的object对象 xff0c C 43 43 会为它分配足够的存放对象所有成员的存储空间 注意 xff1a 为节省存储空间 xff0c
  • C++中引用(&)的用法和应用实例

    对于习惯使用C进行开发的朋友们 xff0c 在看到c 43 43 中出现的 amp 符号 xff0c 可能会犯迷糊 xff0c 因为在C语言中这个符号表示了取地址符 xff0c 但是在C 43 43 中它却有着不同的用途 xff0c 掌握C
  • C++中重载与重写函数区别及虚函数(转载)

    C 43 43 中重载与重写函数区别及虚函数 C 43 43 中的虚函数 virtual function 1 简介 虚函数是C 43 43 中用于实现多态 polymorphism 的机制 核心理念就是通过基类访问派生类定义的函数 假设我
  • c#中的静态构造函数

    静态构造函数是C 的一个新特性 xff0c 其实好像很少用到 不过当我们想初始化一些静态变量的时候就需要用到它了 这个构造函数是属于类的 xff0c 而不是属于哪里实例的 xff0c 就是说这个构造函数只会被执行一次 也就是在创建第一个实例
  • C++中重写与覆写(虚函数virtual)的区别

    本文章已收录于 xff1a 虚函数的情况下调用成员函数时调用的是指向对象的所属类的成员函数例子中为apple class fruit public void func printf 34 fruit n 34 virtual void vf
  • duilib入门问题集

    引入duilib时 请确保引入头文件开始时先引入COMUTIL H头文件 include 34 COMUTIL H 34 include 34 UIlib h 34 duilib基本程序结构 在stdafx h文件中加入 cpp view
  • C#中常用的几种读取XML文件的方法

    XML文件是一种常用的文件格式 xff0c 例如WinForm里面的app config以及Web程序中的web config文件 xff0c 还有许多重要的场所都有它的身影 Xml是Internet环境中跨平台的 xff0c 依赖于内容的
  • C++(1) 指针 new 和delete

    1 概念 new typeName pointer name 61 new typeName delete delete pointer name 注意 xff1a 1 new之后要判断 xff0c 指针是否为NULL xff0c 内存被耗
  • C++的new

    C 43 43 中的new其实是一个很糊弄人的术语 xff0c 它有两种不同的含义 xff0c new运算符 xff08 new operator xff09 和new函数 xff08 operator new xff09 xff0c 值得
  • s32ds

    S32DS使用复位窗口的方式还原 xff1a 在S32DS菜单栏 Windows Perspective Reset Perspective 添加组件 xff0c 自动生成代码 xff1a
  • 在C#中使用SerialPort类实现串口通信 遇到多线程问题

    在C 中使用SerialPort类实现串口通信 遇到多线程问题 在C 中使用SerialPort类实现串口通信 2009年11月01日 星期日 10 03 在 NET work 2 0中提供了SerialPort类 xff0c 该类主要实现
  • [C#]委托和事件(详细讲解)

    引言 委托 和 事件在 Net Framework中的应用非常广泛 xff0c 然而 xff0c 较好地理解委托和事件对很多接触C 时间不长的人来说并不容易 它们就像是一道槛儿 xff0c 过了这个槛的人 xff0c 觉得真是太容易了 xf
  • 连接excel执行Insert Into语句出现“操作必须使用一个可更新的查询”的解决

    C 使用oledb连接excel执行Insert Into语句出现 操作必须使用一个可更新的查询 的解决办法 我发生错误时的环境 xff1a Windows 7 xff0c Framework 4 0 xff0c Microsoft Off

随机推荐

  • 操作excel的一些方法

    更改方法 xff1a public void UpdateExcelFile string filePath string prjId List lt string gt updateColNames List lt string gt c
  • C#中如何创建文件夹

    C 中对文件夹操作需要用到Directory Class 其中提供了创建 删除 移动 枚举等静态方法 该类不能被继承 以下代码实现了创建文件夹 1 2 3 4 if Directory Exists sPath
  • C#获取当前程序运行路径的方法集合

    获取当前进程的完整路径 xff0c 包含文件名 进程名 string str 61 this GetType Assembly Location result X xxx xxx xxx exe exe文件所在的目录 43 exe文件名 获
  • 怎么将excel数据导入到datagridview中

    本人小白 xff0c 想要实现EXCEL文件中的数据导入到datagridview中 xff0c EXCEL中的数据是多行多列 xff0c 行数和列数不确定 xff0c 如何实现导入到datagridview中显示 xff0c 具体的界面如
  • 总结了C#中string.format用法。分享给大家供大家参考。具体分析如下:

    String Format 方法的几种定义 xff1a String Format String Object 将指定的 String 中的格式项替换为指定的 Object 实例的值的文本等效项 String Format String O
  • c#中out、ref和params的用法与区别

    ref和out都对函数参数采用引用传递形式 不管是值类型参数还是引用类型参数 xff0c 并且定义函数和调用函数时都必须显示生命该参数为 ref out形式 两者都可以使函数传回多个结果 两者区别 xff1a 两种参数类型的设计思想不同 x
  • C#代码创建Xml文件

    扩展标记语言XML xff08 eXtensible Markup Language xff09 xff0c 是由W3C组织制定的 做为用于替代HTML语言的一种新型的标记语言 xff0c XML内部有着很多基本标准 xff0c XML就是
  • tftp使用

    tftp服务器路径 xff1a tftp使用命令 xff1a root 64 iTOP 4412 tftp g l module test ko 169 254 231 181 3356 761790 dm96 TxRound 0 for
  • 获取某一扩展名的文件集合

    获取某一扩展名的文件集合 lt summary gt lt param name 61 34 dictoryName 34 gt 目录名 lt param gt lt param name 61 34 fiterName 34 gt 扩展名
  • 使用XmlTextWriter生成XML文件的方法

    使用XmlTextWriter生成XML文件的方法 项目兼容需要生成一系列的xml文件 xff0c 总结了下XML文件的生成基本方式 项目兼容需要生成一系列的xml文件 xff0c 总结了下XML文件的生成基本方式 XmlTextWrite
  • datatable数据类型方法

    本文章已收录于 xff1a 43 Datatable数据类型介绍 简介方法介绍 用法一声明一个datatable类型用法二合并两个结构相同的datatable用法三datatable中数据的计算用法四两种遍历datatable的方法 Dat
  • C#字符串常见操作总结详解

    C 字符串常见操作总结详解 本篇文章是对C 中字符串的常见操作进行了详细的总结介绍 xff0c 需要的朋友参考下 xff08 1 xff09 取字符串长度 lt string gt Length xff08 2 xff09 字符串转为比特码
  • c#读取string类型的xml格式的字符串

    string str 61 lt resultInfo code 61 34 202 34 message 61 34 原密码输入不正确 xff01 34 gt XmlDocument xmlDoc 61 new XmlDocument x
  • C# 截取字符串

    本文章已收录于 xff1a str为要进行截取的字符串 start是第一个关键字 字符串 last是第二个关键字 字符串 public string GetContent string str string start string las
  • C#中文件及文件夾的遍历

    操作文件常用的类有 xff1a File 实用类 xff0c 提供许多静态方法 xff0c 用于移动 删除 和复制文件 Directory 实用类 xff0c 提供许多静态方法 xff0c 用于移动 删除和复制目录 Path 实用类 xff
  • C# 简单的XML读取修改写入

    XML概念 Root XML根节点 xff0c 只能且必须有一个 以上为LinkLibrary Element 节点元素 如Link Attribute 节点属性 如Cat Url Desc Content 内容 xff08 非空白文本 C
  • C# XML 添加,修改,删除Xml节点

    添加xml节点 private void AddXml string image string title XmlDocument xmlDoc 61 new XmlDocument xmlDoc Load Server MapPath 3
  • 使用Activator.CreateInstance完善简单工厂

    前几天在项目中看到别人的工厂类使用Activator CreateInstance 之前用简单工厂都是用switch case xff0c 之前没有用过便查了查资料 xff0c 正是这个方法 43 反射简化了工厂模式 xff0c 在需求增加
  • can协议的数据帧格式

    1 帧起始和帧结束 2 仲裁段 xff1a 3 控制段 xff1a 4 数据段 5 CRC段 6 ACK段
  • C#各种配置文件使用,操作方法总结

    配置文件操作 配置文件一般分为内置配置文和用户自定义配置文件 内置配置文件包括app config web config Settings settings等等 用户自定义配置文件一般是将配置信息放到XML文件或注册表中 xff0c 配置信