c#相關

來源:互聯網
上載者:User

一、net、winform代碼擷取webconfig的內容

webconfig:

<appSettings>
<add key="strConn" value="server=10.1.0.7;database=db;uid=sa;password="/>
</appSettings>

代碼中擷取:

using System.Configuration;
private static string ConnectionString = ConfigurationSettings.AppSettings["strConn"].ToString();

不過上邊的ConfigurationSettings這個已經過時了  需要ConfigurationManager來替換它,不過在目前這裡找不到ConfigurationManager的

只有引用了System.Configuration.dll 才可以找到

private static string ConnectionString = System.Configuration.ConfigurationManager.AppSettings["strConn"].ToString();

net完全可以擷取到、winform好像擷取不到 可以利用擷取xml的方式擷取到 傳送門

二、”沒有可用於當前位置的原始碼“

我遇到的是 修改別人的原始碼出現的錯誤

原因:因為調用的是舊的dll,並且你的路徑和原先項目放的位置不否

解決方案:你只需要清理下出現錯誤的那個小項目、模組,然後重建

詳細點:

右鍵點擊解決方案->屬性->通用屬性->調試源檔案,

看看你的程式有沒有被增加到“不尋找這些源檔案”這個框裡。

再那裡你可以看到是不是你的路徑下沒有呢 呵呵 找到這個源檔案的項目塊:清理+產生

三、:base的用法

public temp2(int fo): base()//調用父類的不帶參數的建構函式
{
Console.WriteLine("child class no paramer");
}
public temp2(int fo) : base(fo)//調用父類的帶參數的建構函式
{
Console.WriteLine("child class");
}
public override void showInfo()//重載父類的 showinfo方法
{
base.showInfo();//調用父類的 showInfo方法
Console.WriteLine("this child's method");
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.