找到 34423 篇文章,主题为编程

C# 的隐藏功能有哪些?

Chandu yadav
更新于 2020年6月21日 12:06:09

309 次浏览

以下是 C# 中隐藏或鲜为人知的实用功能:Lambda 表达式;C# 中的 Lambda 表达式描述了一种模式。它在表达式上下文中包含标记 =>。这被称为“转到”运算符,用于声明 Lambda 表达式。可空类型;C# 提供了一种特殊的数据类型,即可空类型,您可以为其分配正常值范围以及空值。语法如下:? = null;空合并运算符;空合并运算符与可空值类型和引用类型一起使用。它用于将操作数转换为… 阅读更多

C# 支持哪些转义序列?

karthikeya Boyini
更新于 2020年6月21日 12:06:35

123 次浏览

以下示例演示如何在 C# 中显示一些转义字符:示例 using System; using System.Collections.Generic; class Demo {    static void Main() {       Console.WriteLine("Warning!" + '\u0007');       Console.WriteLine("Test \t Demo Text");       Console.WriteLine("This is it!This is on the next line!");    } } C# 中转义序列的完整列表:转义字符 描述 模式 \a 匹配铃声字符,\u0007。\a \b 在字符类中,匹配退格符,\u0008。[\b]{3, } \t 匹配制表符,\u0009。( \w+)\t \r 匹配回车符,\u000D。(\r 不等同于换行符。)\r(\w+) \v 匹配垂直制表符,… 阅读更多

C# 中的类型安全是什么?

Samual Sam
更新于 2020年6月21日 12:13:47

1K+ 次浏览

C# 中的类型安全不允许对象潜入其他对象的内存中。让我们来看一个例子来理解这个概念:示例 public class One {    public int Prop{ get; set;} } public class Two {    public int Prop{get;set;}    public int Prop1{get;set;} } 假设我有一个 Class One 对象:One ob = new One(); 现在你将无法将你的对象 ob 转换为第二个类,即类 Two。如果你转换它,由于 C# 中的类型安全特性,将会出现编译时错误。

在 C# 中转置矩阵

George John
更新于 2020年6月21日 12:11:32

2K+ 次浏览

矩阵的转置将其绕对角线翻转,这将行元素放在列上,列元素放在行上。例如:转置前的矩阵:1 2 3 4 5 6 7 8 9 转置后的矩阵:1 4 7 2 5 8 3 6 9 让我们来看一个在 C# 中实现矩阵转置的示例:示例 using System; public class Demo {    public static void Main() {       int i, j, m, n;       int[, ] arr1 = new int[30, 30];       int[, ] arr2 = new int[30, 30];       Console.Write("Enter the number of ... 阅读更多

C# 中十进制数的八进制等价物是什么?

karthikeya Boyini
更新于 2020年6月21日 12:14:46

138 次浏览

要获取 C# 中十进制数的八进制等价物:首先,对于十进制值,使用 while 循环并将余数存储在为八进制设置的数组中。在这里,我们在数组中找到了它们的模 8。之后,将数字除以 8:while (dec != 0) {    oct[i] = dec % 8;    dec = dec / 8;    i++; } 让我们看看完整的代码。这里,我们的十进制数是 12:示例 using System; namespace Demo {    class Program {       static void Main(string[] args) {       ... 阅读更多

C# 中的 string 和 String 数据类型是什么?

Arjun Thakur
更新于 2020年6月21日 11:53:45

583 次浏览

String 代表 System.String,而 string 是 C# 中 System.String 的别名:例如:string str = "Welcome!"; 它不是必需的,但是当您使用类时通常使用 String:string str = String.Format("Welcome! {0}!", user); 由于 string 是 System.String 的别名。其他数据类型的别名是:示例 object:System.Object string:System.String bool:System.Boolean float:System.Single double:System.Double decimal:System.Decimal byte:System.Byte sbyte:System.SByte short:System.Int16 ushort:System.UInt16 int:System.Int32 uint:System.UInt32 long:System.Int64 ulong:System.UInt64 char:System.Char C# 中的 String 类型允许您将任何字符串值赋给变量。string 类型是 System.String 的别名… 阅读更多

C# 中的静态或固定长度数组是什么?

Samual Sam
更新于 2020年6月21日 11:56:11

1K+ 次浏览

静态数组是一种大小固定的数据结构。让我们来看一个 C# 中静态数组的示例。这里的数据保持不变,即固定:static string[] _fruits = new string[] {    "apple",    "mango" }; 现在让我们来看一个在 C# 中创建和访问静态数组的完整示例:示例 using System; class Demo {    static void Main() {       foreach (string fruits in Program.Fruits) {          Console.WriteLine(fruits);       }    } } public static class Program {    static string[] _fruits = new string[] {       "apple",       "mango"    };    public static string[] Fruits {       get {          return _fruits;       }    } }

C# 中的 sealed 修饰符是什么?

Ankith Reddy
更新于 2020年6月21日 11:57:56

395 次浏览

当您在 C# 中对方法使用 sealed 修饰符时,该方法将失去其重写功能。sealed 方法应该是派生类的一部分,并且该方法必须是重写方法。让我们来看一个示例:以下示例不允许您重写方法 display(),因为它对 ClassTwo 派生类具有 sealed 修饰符:ClassOne 是我们的基类,而 ClassTwo 和 ClassThree 是派生类:示例 class ClassOne {    public virtual void display() {       Console.WriteLine("baseclass");    } } class ClassTwo : ClassOne {    public sealed override ... 阅读更多

C# 中的标点符号是什么?

karthikeya Boyini
更新于 2020年6月21日 11:58:22

415 次浏览

标点符号在 C# 中用作特殊符号来分组或划分代码。它包括:] () {}, ; * = # 例如,= 包含在类中,甚至在声明变量时也是如此。语句以分号结尾:int a = 10; 在类中,使用大括号:class Demo { } 声明字典时:var d = new Dictionary(5); 它也用于声明和初始化列表:List myList = new List() {    "mammals",    "reptiles",    "amphibians" };

C# 中的扩展程序提供程序组件是什么?

George John
更新于 2020年6月21日 11:58:57

128 次浏览

要为其他组件提供属性,可以使用扩展程序提供程序。让我们考虑一个 TooTtip 组件的示例。您将组件添加到窗体中。这会为每个控件设置一个 ToolTip 属性。相同的属性不在受攻击的 PropertyGrid 控件下。myTooltip1.SetToolTip(btn1, "This is ToolTip!"); 让我们看看如何实现扩展程序提供程序组件:首先,定义一个组件:public class MyExtender : IExtenderProvider {...}IExtenderProvider 定义:public interface IExtenderProvider {    bool newExtend(object extendeNew); } 现在您需要实现 newExtend 方法。这是为了对每个相关的组件或控件返回 true。

广告
© . All rights reserved.