本文将分享Java:如何从System.console的详细内容,并且还将对获取输入进行详尽解释,此外,我们还将为大家带来关于C#System.Collections.SortedList、c#–Ne
本文将分享Java:如何从System.console的详细内容,并且还将对获取输入进行详尽解释,此外,我们还将为大家带来关于C# System.Collections.SortedList、c# – Newtonsoft.Json.Linq.JArray’输入’System.Collections.Generic.IEnumerable、C# 中的 System.Console 类及其方法是什么?、Console.Read()和Console.ReadLine()之间的区别?的相关知识,希望对你有所帮助。
本文目录一览:- Java:如何从System.console()获取输入(java怎么获取用户输入的数据)
- C# System.Collections.SortedList
- c# – Newtonsoft.Json.Linq.JArray’输入’System.Collections.Generic.IEnumerable
- C# 中的 System.Console 类及其方法是什么?
- Console.Read()和Console.ReadLine()之间的区别?
Java:如何从System.console()获取输入(java怎么获取用户输入的数据)
我正在尝试使用Console类从用户获取输入,但是在调用时返回空对象System.console()
。使用System.console之前我是否需要更改任何内容?
Console co=System.console();System.out.println(co);try{ String s=co.readLine();}
答案1
小编典典使用控制台读取输入(仅在IDE外部可用):
System.out.print("Enter something:");String input = System.console().readLine();
另一种方法(适用于所有地方):
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class Test { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter String"); String s = br.readLine(); System.out.print("Enter Integer:"); try { int i = Integer.parseInt(br.readLine()); } catch(NumberFormatException nfe) { System.err.println("Invalid Format!"); } }}System.console()在IDE中返回null。
因此,如果你真的需要使用System.console()
C# System.Collections.SortedList
1 using System;
2 using System.Collections;
3 public class SamplesSortedList {
4
5 public static void Main() {
6
7 // Creates and initializes a new SortedList.
8 SortedList mySL = new SortedList();
9 mySL.Add("Third", "!");
10 mySL.Add("Second", "World");
11 mySL.Add("First", "Hello");
12
13 // Displays the properties and values of the SortedList.
14 Console.WriteLine( "mySL" );
15 Console.WriteLine( " Count: {0}", mySL.Count );
16 Console.WriteLine( " Capacity: {0}", mySL.Capacity );
17 Console.WriteLine( " Keys and Values:" );
18 PrintKeysAndValues( mySL );
19 }
20
21
22 public static void PrintKeysAndValues( SortedList myList ) {
23 Console.WriteLine( "\t-KEY-\t-VALUE-" );
24 for ( int i = 0; i < myList.Count; i++ ) {
25 Console.WriteLine( "\t{0}:\t{1}", myList.GetKey(i), myList.GetByIndex(i) );
26 }
27 Console.WriteLine();
28 }
29 }
30 /*
31 This code produces the following output.
32
33 mySL
34 Count: 3
35 Capacity: 16
36 Keys and Values:
37 -KEY- -VALUE-
38 First: Hello
39 Second: World
40 Third: !
41 */
构造函数
SortedList() | 初始化 SortedList 类的新实例,该实例为空、具有默认初始容量并根据 IComparable接口(此接口由添加到 SortedList 对象中的每个键实现)进行排序。 |
SortedList(IComparer) | 初始化 SortedList 类的新实例,该实例为空、具有默认初始容量并根据指定的 IComparer 接口进行排序。 |
SortedList(IComparer, Int32) | 初始化 SortedList 类的新实例,该实例为空、具有指定的初始容量并根据指定的 IComparer 接口排序。 |
SortedList(IDictionary) | 初始化 SortedList 类的新实例,该实例包含从指定字典复制的元素、具有与所复制的元素数相同的初始容量并根据由每个键实现的 IComparable 接口排序。 |
SortedList(IDictionary, IComparer) | 初始化 SortedList 类的新实例,该实例包含从指定字典复制的元素、具有与所复制的元素数相同的初始容量并根据指定的 IComparer 接口排序。 |
SortedList(Int32) | 初始化 SortedList 类的新实例,该实例为空、具有指定的初始容量并且根据 IComparable 接口(此接口由添加到 SortedList 对象的每个键实现)进行排序。 |
属性
Capacity | 获取或设置 SortedList 对象的容量。 |
Count | 获取 SortedList 对象中包含的元素数。 |
IsFixedSize | 获取一个值,该值指示 SortedList 对象是否具有固定大小。 |
IsReadOnly | 获取一个值,该值指示 SortedList 对象是否为只读。 |
IsSynchronized | 获取一个值,该值指示对 SortedList 对象的访问是否同步(线程安全)。 |
Item[Object] | 获取或设置与 SortedList 对象中的特定键相关联的值。 |
Keys | 获取 SortedList 对象中的键。 |
SyncRoot | 获取一个对象,该对象可用于同步对 SortedList 对象的访问。 |
Values | 获取 SortedList 对象中的值。 |
方法
Add(Object, Object) | 将带有指定键和值的元素添加到 SortedList 对象。 |
Clear() | 从 SortedList 对象中移除所有元素。 |
Clone() | 创建 SortedList 对象的浅表副本。 |
Contains(Object) | 确定 SortedList 对象是否包含特定键。 |
ContainsKey(Object) | 确定 SortedList 对象是否包含特定键。 |
ContainsValue(Object) | 确定 SortedList 对象是否包含特定值。 |
CopyTo(Array, Int32) | 从指定数组索引开始将 SortedList 元素复制到一维 Array 对象中。 |
Equals(Object) | 确定指定的对象是否等于当前对象。 (Inherited from Object) |
GetByIndex(Int32) | 获取 SortedList 对象的指定索引处的值。 |
GetEnumerator() | 返回一个循环访问 IDictionaryEnumerator 对象的 SortedList 对象。 |
GetHashCode() | 作为默认哈希函数。 (Inherited from Object) |
GetKey(Int32) | 获取 SortedList 对象的指定索引处的键。 |
GetKeyList() | 获取 SortedList 对象中的键。 |
GetType() | 获取当前实例的 Type。 (Inherited from Object) |
GetValueList() | 获取 SortedList 对象中的值。 |
IndexOfKey(Object) | 返回 SortedList 对象中指定键的从零开始的索引。 |
IndexOfValue(Object) | 返回指定的值在 SortedList 对象中第一个匹配项的从零开始的索引。 |
MemberwiseClone() | 创建当前 Object 的浅表副本。 (Inherited from Object) |
Remove(Object) | 从 SortedList 对象中移除带有指定键的元素。 |
RemoveAt(Int32) | 移除 SortedList 对象的指定索引处的元素。 |
SetByIndex(Int32, Object) | 替换 SortedList 对象中指定索引处的值。 |
Synchronized(SortedList) | 返回 SortedList 对象的同步(线程安全)包装。 |
ToString() | 返回表示当前对象的字符串。 (Inherited from Object) |
TrimToSize() | 将容量设置为 SortedList 对象中元素的实际数目。 |
c# – Newtonsoft.Json.Linq.JArray’输入’System.Collections.Generic.IEnumerable
这是我在客户端的代码:
public IEnumerable<Model.Print> Get() { var print = new List<Model.Print>(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(Shared.URL); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(Shared.HeaderType)); var response = client.GetAsync(route + "?" + GeneralTags.CUSTOMER_REF + "=" + new Guid().ToString()).Result; if (response.IsSuccessstatusCode) { string strjson = response.Content.ReadAsstringAsync().Result; var jObj2 = (IEnumerable<Model.Print>)JsonConvert.DeserializeObject(strjson); } else { evError(new Exception(String.Format("{0}: {1}",(int)response.StatusCode,response.ReasonPhrase)),ErrorTags.PRINT_GET); } } return print; }
但我在这一行上收到错误:
var jObj2 = (IEnumerable<Model.Print>)JsonConvert.DeserializeObject(strjson);
错误是:
'Newtonsoft.Json.Linq.JArray' to type 'System.Collections.Generic.IEnumerable`1[InformedWorkerServer.Model.Print]'.
strjson包含一个值:
[ {"PrintId":1,"PrintRef":"00000000-0000-0000-0000-000000000000","Header":"header","TC":"tc","CompanyRef":"00000000-0000-0000-0000-000000000000"},{"PrintId":2,"PrintRef":"39a10cee-7cb3-4ed3-aec2-293761eed96d","CompanyRef":"00000000-0000-0000-0000-000000000000"}]
我错过了什么?
解决方法
var jObj2 = JsonConvert.DeserializeObject<List<Model.Print>>(strjson);
C# 中的 System.Console 类及其方法是什么?
C# 中的 System.Console 类代表控制台应用程序的标准输入、输出和错误流。
以下是 System.Console 类的一些方法 -
参考:MSDN系统类方法8Sr.No | 方法及说明 |
---|---|
1 |
Beep() 播放蜂鸣声通过控制台扬声器。 |
2 |
Beep(Int32,Int32) 通过控制台扬声器播放指定频率和持续时间的蜂鸣声。 |
3 |
清除() 清除控制台缓冲区和相应控制台窗口的显示信息。 |
4 |
移动缓冲区(Int32,Int32,Int32,Int32,Int32,Int32) p> 将屏幕缓冲区的指定源区域复制到指定的目标区域。 |
5 |
MoveBufferArea(Int32,Int32,Int32,Int32,Int32,Int32, Char, ConsoleColor, ConsoleColor) 将屏幕缓冲区的指定源区域复制到指定的目标区域。 |
6 |
OpenStandardError() 获取标准错误流。 |
7 |
OpenStandardError(Int32) 获取标准错误流,该流设置为指定的缓冲区大小。 |
OpenStandardInput() 获取标准输入流。 |
|
9 |
OpenStandardInput(Int32) 获取标准输入流,该流设置为指定的缓冲区大小。 td> |
10 | OpenStandardOutput() 获取标准输出流。 |
11 |
OpenStandardOutput(Int32) 获取标准输出流,该流设置为指定的缓冲区大小. |
12 |
Read() 从标准输入流读取下一个字符。 |
13 |
ReadKey() 获取用户按下的下一个字符或功能键。按下的键将显示在控制台窗口中。 |
以上就是C# 中的 System.Console 类及其方法是什么?的详细内容,更多请关注php中文网其它相关文章!
Console.Read()和Console.ReadLine()之间的区别?
我是该领域的新手,我非常困惑:Console.Read()
和之间的真正区别是Console.ReadLine()
什么?
答案1
小编典典Console.Read()
从标准输入中仅读取下一个字符,并Console.ReadLine()
从标准输入流中读取下一行字符。
如果是“控制台应用程序”,则标准输入是从应用程序控制台UI中用户键入的单词输入的。尝试通过Visual Studio创建它,然后自己查看。
我们今天的关于Java:如何从System.console和获取输入的分享已经告一段落,感谢您的关注,如果您想了解更多关于C# System.Collections.SortedList、c# – Newtonsoft.Json.Linq.JArray’输入’System.Collections.Generic.IEnumerable、C# 中的 System.Console 类及其方法是什么?、Console.Read()和Console.ReadLine()之间的区别?的相关信息,请在本站查询。
本文标签: