2019年11月29日 星期五

[C#] Lambda All() check ListA all in ListB

public static bool ContainsAll<T>(IEnumerable<T> source, IEnumerable<T> values)
{
    return values.All(value => source.Contains(value));
}

2019年11月26日 星期二

新增 net core project


$ dotnet new web -o <專案名稱>
dotnet help 可以查看專案型態的參數
安裝npm $ npm install 檢查npm安裝版本
$ npm -v

init npm
$npm init
如果沒有要設定專案資訊 直接Enter到底
結束之後 會再package.json寫入設定

npm安裝套件 ex jquery
$ npm install jquery

安裝LibMan
$ dotnet tool install -g Microsoft.Web.LibraryManager.Cli

Run
$ dotnet run


Ref microsoft microsoft-SingleR install

2019年11月24日 星期日

.Net Core Console使用依賴注入

  1. public static async Task Main(string[] args)
  2. {
  3.  
  4. // 取得設定檔
  5. IConfiguration config = new ConfigurationBuilder()
  6. .AddJsonFile("appsettings.json", true, true)
  7. .Build();
  8. // 建立容器
  9. var serviceCollection = new ServiceCollection();
  10.  
  11. // 註冊服務
  12. serviceCollection.AddTransient();
  13. serviceCollection.AddTransient();
  14. // 加入SqlServer 連線字串
  15. serviceCollection.AddDbContext(options => options.UseSqlServer(config["ConnectionStrings:DefaultConnection"]));
  16. // 建立依賴服務提供者
  17. var serviceProvider = serviceCollection.BuildServiceProvider();
  18. // 執行
  19. await serviceProvider.GetRequiredService().Run();
  20. }

C# 比較字串不分大小寫

除了把字串ToUpper() 或 ToLower() 以外

還可以用 String.Compare()
  1. //最後一個參數改成true 就可以忽略大小寫
  2. String.Compare(strSource, strTarget, true)
回傳為0 即相等


而另外一種我最常用來做搜尋的方法是Contains()

  1. sourceString.Contains("Search-Word", StringComparison.InvariantCultureIgnoreCase,
  2. new System.Globalization.CultureInfo("en-US")));

2019年3月4日 星期一

移除警告



當出現很多警告

如果要讓警告消失,用NotePad++ 開啟專案檔編輯,
加入 <DependsOnNETStandard>true</DependsOnNETStandard>






這樣一來 警告就不會再出現了