找到 34423 篇文章,关于编程

C# 的隐藏特性有哪些?

Chandu yadav
更新于 2020-06-21 12:06:09

309 次浏览

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

C# 支持哪些转义序列?

karthikeya Boyini
更新于 2020-06-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-06-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-06-21 12:11:32

2K+ 次浏览

矩阵的转置将其沿对角线翻转,这将把行元素放在列上,列元素放在行上。例如 -转置前的矩阵:123 456 789转置后的矩阵:147 258 369让我们在 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-06-21 12:14:46

138 次浏览

要获取 C# 中十进制数的八进制等价物 -首先,对于十进制值,使用 while 循环并将余数存储在为八进制设置的数组中。在这里,我们在数组中找到了它们的 mod 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-06-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.CharC# 中的 String 类型允许您将任何字符串值分配给变量。string 类型是 System.String 的别名... 阅读更多

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

Samual Sam
更新于 2020-06-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-06-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-06-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-06-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.