找到 34423 篇文章,关于编程
2K+ 次浏览
首先,设置十六进制字符串 −string str = "7D";现在,使用 Convert.ToSByte() 方法将十六进制字符串转换为十六进制数字 −Console.WriteLine(Convert.ToSByte(str, 16));让我们看看完整的代码 −示例 在线演示using System; namespace Demo { public class Program { public static void Main(string[] args) { string str = "7D"; Console.WriteLine(Convert.ToSByte(str, 16)); } } }输出125另一种将十六进制字符串转换为十六进制数字的方法 −示例 在线演示using System; namespace Demo { public class Program { public static void Main(string[] args) { string str = "7D"; Console.WriteLine(Convert.ToInt32(str, 16)); } } }输出125
836 次浏览
首先,设置一个元组 −Tuple t = Tuple.Create(99,53);现在,将元组转换为数组 −int[] arr = new int[]{t.Item1, t.Item2};以下是将元组转换为数组的代码 −示例 在线演示using System; using System.Linq; using System.Collections.Generic; namespace Demo { public class Program { public static void Main(string[] args) { Tuple t = Tuple.Create(99,53); int[] arr = new int[]{t.Item1, t.Item2}; foreach (int val in arr) { Console.WriteLine(val); } } } }输出99 53
393 次浏览
要使用递归获得十进制的二进制值,首先设置十进制数 −int dec = 30;现在将值传递给函数 −public int displayBinary(int dec) { }现在,检查条件,直到十进制值为 0,并使用递归获取十进制数的模 2,如下所示。递归调用将使用 dec/2 值再次调用函数 −public int displayBinary(int dec) { int res; if (dec != 0) { res = (dec % 2) + 10 * displayBinary(dec / 2); Console.Write(res); return ... 阅读更多
218 次浏览
要将两个已排序的数组合并到列表中,首先设置两个已排序的数组 −int[] array1 = { 1, 2 }; int[] array2 = { 3, 4 };将其添加到列表并合并 −var list = new List(); for (int i = 0; i < array1.Length; i++) { list.Add(array1[i]); list.Add(array2[i]); }现在,使用 ToArray() 方法转换回数组,如下所示 −示例 在线演示using System; using System.Collections.Generic; public class Program { public static void Main() { int[] array1 = { 56, 70, 77}; int[] array2 = ... 阅读更多
435 次浏览
要检查所有元音,首先设置检查条件 −string res = str.Where(chk =< "aeiouAEIOU".Contains(chk)).Distinct();上面,我们使用了字符串 −string str = "the quick brown fox jumps over the lazy dog";现在,使用 Any() 方法检查字符串是否包含任何元音 −if(!res.Any()) Console.WriteLine("No vowels!");循环遍历字符串以获取元音 −示例 在线演示using System; using System.Linq; public class Program { public static void Main() { string str = "the quick brown fox jumps over the lazy dog"; var res = str.Where(chk =< "aeiouAEIOU".Contains(chk)).Distinct(); ... 阅读更多
959 次浏览
首先,设置列表 −List myList = new List () { 5, 10, 7 };现在,将变量的值设置为 1,这将有助于我们进行乘法 −int prod = 1;循环遍历并获取乘积 −foreach(int i in myList) { prod = prod*i; }以下是代码 −示例 在线演示using System; using System.Collections.Generic; public class Program { public static void Main() { List myList = new List() { 5, 10, 7 }; Console.WriteLine("List: "); foreach(int i in myList) { Console.WriteLine(i); } int prod = 1; foreach(int i in myList) { prod = prod*i; } Console.WriteLine("Product: {0}",prod); } }输出List: 5 10 7 Product: 350
2K+ 次浏览
首先,将数字设置为字符串 −string num = "1000000.8765";现在,对小数点前后的数字进行不同的处理 −string withoutDecimals = num.Substring(0, num.IndexOf(".")); string withDecimals = num.Substring(num.IndexOf("."));使用 ToString() 方法设置 1000 分隔符的格式 −ToString("#,##0")以下是显示带有逗号作为千位分隔符的数字的完整代码 −示例 在线演示using System; public class Program { public static void Main() { string num = "1000000.8765"; string withoutDecimals = num.Substring(0, num.IndexOf(".")); string withDecimals = num.Substring(num.IndexOf(".")); withoutDecimals = Convert.ToInt32(withoutDecimals).ToString("#,##0"); Console.WriteLine(withoutDecimals + withDecimals); } }输出1,000,000.8765
1K+ 次浏览
假设字符串是 −string str = "Never Give Up!";首先,拆分每个单词 −string[] strSplit = str.Split();现在,循环遍历每个单词并使用子字符串方法显示首字母,如下面的代码所示 −示例 在线演示using System; public class Program { public static void Main() { string str = "Never Give Up!"; Console.WriteLine("Initial String= "+str); Console.WriteLine("Displaying first letter of each word..."); string[] strSplit = str.Split(); foreach (string res in strSplit) { Console.Write(res.Substring(0,1)); } } }输出Initial String= Never Give Up! Displaying first letter of each word... NGU
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP