找到 34423 篇文章 关于编程

C# CompareOrdinal() 方法

AmitDiwan
更新于 2019年12月3日 10:16:17

275 次浏览

C# 中的 CompareOrdinal() 方法用于通过评估每个字符串中相应 Char 对象的数值来比较两个指定的 String 对象。语法public static int CompareOrdinal (string str1, string str2);上面,str1 和 str2 是要比较的字符串。返回值小于零,则 str1 < str2;等于零,则 str1 = str2;大于零,则 str1 > str2。示例 在线演示using System; public class Demo {    public static void Main(string[] args) {       string s1 = "Amy";       string s2 = "Katie";       string s3 = s2;   ... 阅读更多

C++ 程序生成验证码并验证用户

Ayush Gupta
更新于 2019年12月3日 10:13:06

709 次浏览

在本教程中,我们将讨论一个生成验证码并验证用户的程序。为此,我们将向用户提供一个随机字符串,并要求他重新输入相同的字符串。然后必须检查给定的字符串和输入字符串是否匹配。验证码应该是完全随机的系统生成的,包含 a-z、A-Z 和 0-9。示例#include using namespace std; // 检查字符串是否相同 bool check_string(string &captcha, string &user_captcha){    return captcha.compare(user_captcha) == 0; } // 生成一个随机字符串作为验证码 string gen_captcha(int n){    time_t t;    srand((unsigned)time(&t));    char *chrs = "abcdefghijklmnopqrstuvwxyzABCDEFGHI" "JKLMNOPQRSTUVWXYZ0123456789"; ... 阅读更多

C# 中的 StringBuilder.ToString() 方法

AmitDiwan
更新于 2019年12月3日 09:57:10

2K+ 次浏览

C# 中的 StringBuilder.ToString() 方法用于将 StringBuilder 的值转换为 String。语法语法如下:public override string ToString (); public string ToString (int begnIndex, int len);上面,参数 begnIndex 是此实例中子字符串的起始位置,而 len 是子字符串的长度。示例让我们来看一个示例: 在线演示using System; using System.Text; public class Demo{    public static void Main(){       StringBuilder strBuilder = new StringBuilder("Katie");       Console.WriteLine("String = "+strBuilder.ToString());       Console.WriteLine("StringBuilder capacity = "+strBuilder.Capacity);       Console.WriteLine("StringBuilder length = "+strBuilder.Length); ... 阅读更多

C# 中的 Random.Next() 方法

AmitDiwan
更新于 2019年12月3日 09:54:27

3K+ 次浏览

C# 中的 Random.Next() 方法用于返回一个非负随机整数。语法语法如下:public virtual int Next (); public virtual int Next (int maxVal);上面,maxVal 参数是将要生成的随机数的独占上限。示例让我们来看一个示例: 在线演示using System; public class Demo {    public static void Main(){       Random r = new Random();       Console.WriteLine("随机数.....");       for (int i = 1; i

C# 中的 SortedDictionary.Values 属性

AmitDiwan
更新于 2019年12月3日 09:52:19

108 次浏览

C# 中的 SortedDictionary.Value 属性用于获取包含 SortedDictionary 中值的集合。语法语法如下:public System.Collections.Generic.SortedDictionary.ValueCollection Values { get; }示例让我们来看一个示例: 在线演示using System; using System.Collections; using System.Collections.Generic; public class Demo {    public static void Main(){       SortedDictionarysortedDict = new SortedDictionary();       sortedDict.Add(1, "Ultrabook");       sortedDict.Add(2, "Alienware");       sortedDict.Add(3, "Notebook");       sortedDict.Add(4, "Connector");       sortedDict.Add(5, "Flash Drive");       sortedDict.Add(6, "SSD");       sortedDict.Add(7, "HDD");       sortedDict.Add(8, "Earphone");       Console.WriteLine("SortedDictionary ... 阅读更多

C# 中的 Double.IsNegativeInfinity() 方法

AmitDiwan
更新于 2019年12月3日 09:48:11

37 次浏览

C# 中的 Double.IsNegativeInfinity() 方法用于返回一个值,该值指示指定的数字是否计算为负无穷大。语法语法如下:public static bool IsNegativeInfinity (double val);上面,val 是一个双精度浮点数。示例让我们来看一个示例: 在线演示using System; public class Demo {    public static void Main(){       double d = 0.0/0;       Console.WriteLine("Double Value = "+d);       Console.WriteLine("HashCode of Double Value = "+d.GetHashCode());       TypeCode type = d.GetTypeCode();       Console.WriteLine("TypeCode of Double Value = "+type);       Console.WriteLine("Positive Infinity? = "+Double.IsInfinity(d));   ... 阅读更多

带示例的 C# 中的 Boolean.GetTypeCode() 方法

AmitDiwan
更新于 2019年12月3日 09:46:18

46 次浏览

C# 中的 Boolean.GetTypeCode() 方法用于返回 Boolean 值类型的类型代码。语法语法如下:public TypeCode GetTypeCode ();示例让我们来看一个示例: 在线演示using System; public class Demo {    public static void Main(String[] args){       string str = "JackSparrow!";       bool val = true;       char[] arr = { 'J', 'a'};       Console.WriteLine("String = "+str);       Console.WriteLine("String (after trim) = " + str.Trim(arr));       Console.WriteLine("String (Hashcode) = "+str.GetHashCode());       Console.WriteLine("Bool (Hashcode) = "+val.GetHashCode());       Console.WriteLine("Bool ... 阅读更多

C# 中的 StringBuilder.EnsureCapacity() 方法

AmitDiwan
更新于 2019年12月3日 09:43:35

90 次浏览

C# 中的 StringBuilder.EnsureCapacity() 方法用于确保此 StringBuilder 实例的容量至少为指定值。语法语法如下:public int EnsureCapacity (int capacity);上面,参数 capacity 是要确保的最小容量。示例让我们来看一个示例: 在线演示using System; using System.Text; public class Demo{    public static void Main(){       StringBuilder strBuilder = new StringBuilder("jhbjhb");       Console.WriteLine("String = "+strBuilder);       Console.WriteLine("StringBuilder capacity= "+strBuilder.Capacity);       strBuilder.EnsureCapacity(20);       Console.WriteLine("StringBuilder capacity= "+strBuilder.Capacity);       char[] arr = new char[5] {'a', 'b', 'c', ... 阅读更多

C# 中的 IsNullOrEmpty() 方法

AmitDiwan
更新于 2019年12月3日 09:39:06

1K+ 次浏览

C# 中的 IsNullOrEmpty() 方法用于判断指定的字符串是否为 null 或空字符串("")。语法语法如下:public static bool IsNullOrEmpty (string val);其中,值 val 是要测试的字符串。示例让我们来看一个例子: 演示使用 System; public class Demo { public static void Main(){ string str1 = "Amit"; string str2 = " "; Console.WriteLine("Is string1 null or empty? = "+string.IsNullOrEmpty(str1)); Console.WriteLine("Is string2 null or empty? = "+string.IsNullOrEmpty(str2)); } }输出这将产生以下输出:Is string1 null ... 阅读更多

C# 中的 Int64.ToString() 方法

AmitDiwan
更新于 2019年12月3日 09:36:53

403 次浏览

C# 中的 Int64.ToString() 方法用于将此实例的数值转换为其等效的字符串表示形式。语法语法如下:public override string ToString (); public string ToString (string format);其中,参数 format 是一个数字格式字符串。示例让我们来看一个例子: 演示使用 System; public class Demo { public static void Main(){ long val1 = 0; long val2 = Int64.MaxValue; Console.WriteLine("Value1 = "+val1.ToString()); Console.WriteLine("Value2 = "+val2.ToString()); Console.WriteLine("Are they equal? = "+val1.Equals(val2)); Console.WriteLine("Value1 (HashCode) = "+val1.GetHashCode()); ... 阅读更多

广告
© . All rights reserved.