[关闭]
@Aiti 2019-07-18T05:45:35.000000Z 字数 1576 阅读 240

.Net入门


学习笔记、持续更新
学习网址:https://docs.microsoft.com/zh-cn/dotnet/


C#相关


  1. 扩展方法
    扩展方法使你能够向现有类型“添加”方法,而无需创建新的派生类型、重新编译或以其他方式修改原始类型。 最常见的扩展方法是 LINQ 标准查询运算符,它将查询功能添加到现有的 System.Collections.IEnumerable 和 System.Collections.Generic.IEnumerable 类型。 若要使用标准查询运算符,请先使用 using System.Linq 指令将它们置于范围中。 然后,任何实现了 IEnumerable 的类型看起来都具有 GroupBy、OrderBy、Average 等实例方法。
    示例
    以下示例实现 CustomExtensions.StringExtension 类中名为 WordCount 的扩展方法。 此方法对 String 类进行操作,该类指定为第一个方法参数。 将 CustomExtensions 命名空间导入应用程序命名空间,并在 Main 方法内部调用此方法。
  1. using System.Linq;
  2. using System.Text;
  3. using System;
  4. namespace CustomExtensions
  5. {
  6. public static class StringExtension
  7. {
  8. public static int WordCount(this String str)
  9. {
  10. return str.Split(new char[] {' ', '.','?'}, StringSplitOptions.RemoveEmptyEntries).Length;
  11. }
  12. }
  13. }
  14. ----------
  15. namespace Extension_Methods_Simple
  16. {
  17. // Import the extension method namespace.
  18. using CustomExtensions;
  19. class Program
  20. {
  21. static void Main(string[] args)
  22. {
  23. string s = "The quick brown fox jumped over the lazy dog.";
  24. // Call the method as if it were an
  25. // instance method on the type. Note that the first
  26. // parameter is not specified by the calling code.
  27. int i = s.WordCount();
  28. System.Console.WriteLine("Word count of s is {0}", i);
  29. }
  30. }
  31. }

为服务器应用选择.NET Core或.NET Framework

在以下情况,对服务器应用程序使用 .NET Core:
.NET Core 是开放源代码通用开发平台,由 Microsoft 和 .NET 社区在 GitHub 上共同维护。 它跨平台(支持 Windows、macOS 和 Linux),并且可用于生成设备、云和 IoT 应用程序。

在以下情况,对服务器应用程序使用 .NET Framework :
.NET Framework 是用于为 Web、Windows、Windows Phone、Windows Server 和 Microsoft Azure 构建应用的开发平台。 它包含公共语言运行时 (CLR) 和 .NET Framework 类库,其中包括各种功能和对许多行业标准的支持。

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注