第 16 题
8 W3 K- G- t; p* h% {4 k7 Q你正在写一个应用。它利用 SOAP 去和其他应用交换数据。你使用一个从 ArrayList 继承的 2 M7 R' S. M1 c6 n
Department 类作为数据对象发送给另一个应用。Department 被命名为 dept。为了通过 SOAP 8 F" j& q# [7 m2 {4 p
进行传送,你需要保证 Department 对象被序列化。你应该使用下面那个代码进行 dept 的序列
- [: g5 b6 @$ _4 k# D; d化?
' p) o# D: P& d6 \6 m) E, s, U6 Y% ZA. SoapFormatter formatter = new SoapFormatter();byte[] buffer = new
; s# w; a5 P, J( ^7 Ibyte[dept.Capacity];MemoryStream stream = new MemoryStream(buffer); foreach , R$ p! n5 H2 j9 T
(object o in dept) {formatter.Serialize(stream, o);} : m% z5 t7 W( |+ [/ ^1 L' B) ?
B. SoapFormatter formatter = new SoapFormatter();byte[] buffer = new ; C' T# I/ \0 }3 K' B2 k
byte[dept.Capacity];MemoryStream stream = new MemoryStream(buffer);
8 h7 y: w' @4 e0 K2 A. x- Nformatter.Serialize(stream, dept); ; Z4 x1 }- h1 b' Y d" K: y& z% T
C. SoapFormatter formatter = new SoapFormatter();MemoryStream stream = new
, w5 H- y0 Q1 f% AMemoryStream();foreach (object o in dept) { 8 E6 T' {- L% l0 A0 a
Formatter.Serialize(stream, o);} 6 |& F9 a' l/ R+ w) b, {8 z
D. SoapFormatter formatter = new SoapFormatter();MemoryStream stream = new 1 n! r1 A2 E5 R
MemoryStream(); formatter.Serialize(stream, dept);
0 ~- J* y, h7 U6 l2 R答案: D $ K; g. F% {; K) ?$ g# J
+ B0 H7 r) y! c' G8 L/ ?, W
第 17 题 l/ e5 s3 g% i$ n8 f
你需要写一个完成如下任务的代码段: $ ]+ y1 `) i! B0 T& r
1) 查找所有暂停的服务 ' J' Y$ @5 q% ^9 B0 J0 y
2) 把服务的显示名称增加到集合中
* R1 {) t( W h请问,你应该使用那个代码段? & D& @8 S+ a ]8 Y2 [
A. Dim searcher As ManagementObjectSearcher = _New ManagementObjectSearcher( _ - V, E1 ~: H. F' q
"Select * from Win32_Service where State = ’Paused’")
2 _7 |/ H5 P/ `, U& L0 J7 }For Each svc As
% V' F4 ] X1 h. f' }ManagementObject In searcher.Get() 5 ^( a" L$ t2 E& O
Collection1.Add(svc("DisplayName")) 7 a ~ ^# o8 z' D# l, z8 x
Next
: [! Z" ~: S- N- |; g1 @) a) @( M' BB. Dim searcher As ManagementObjectSearcher = _New ManagementObjectSearcher ( _ ) z9 L7 ?. O6 x
"Select * from Win32_Service", "State = ’Paused’")
8 }& h8 U5 x4 g" Y/ XFor Each svc As ManagementObject In searcher.Get()
" V* @! ?% [4 V" UCollection1.Add(svc("DisplayName")) ( V, M1 q$ i" z5 \. G
Next
" B7 K& G: t9 ^5 @; d: Y9 c- UC. Dim searcher As ManagementObjectSearcher = _ New ManagementObjectSearcher( _
! i+ v$ f2 d% w1 r* O"Select * from Win32_Service") 1 k( ?0 N, g. u% ^5 J P' t
For Each svc As ManagementObject In searcher.Get() ! g9 B4 W, Q0 l8 S# g0 N5 v
If svc("State").ToString() = "’Paused’" Then
7 {/ C) V# @9 m9 m- MCollection1.Add(svc("DisplayName"))
( Y. b7 u& v; i0 P! i9 E- r" zEnd If
: {( M( ~5 s# Z4 VNext
8 H% f$ y% }* i' p0 SD. Dim searcher As New ManagementObjectSearcher()searcher.Scope = New 1 Y4 [$ w( X" ]2 ?$ \& P& O
ManagementScope("Win32_Service") 4 i! m+ C9 [+ m1 |% _: _
For Each svc As ManagementObject In searcher.Get() - H: a' s5 X3 k: W# x/ D% D K2 A
If svc("State").ToString() = "Paused" Then
) N; X/ G% \" f1 n/ W6 TCollection1.Add(svc("DisplayName"))
) F! ~4 y) x* h: }/ u: ^End If
( c& ]0 n; s& x- f. O% |# ], uNext ( a/ I' @/ d: w' ~9 ^
答案: A 3 H: B. [# O# x6 S
4 N0 s& W+ C; E4 K+ m) z$ [* J
第 18 题 $ W- U" L' j/ B& l6 ~4 }6 R1 u9 }$ L
你正在写一个接收字符串参数 message 的方法。你的方法必须截取 message 参数为单独的
4 W6 M1 c' W( R7 K文本行并且传递每一行给另一个方法 Process。你应该使用那个代码段? 7 a5 J( _) G9 h! X- Q, Y
A. Dim reader As New & X# `' P. c$ u% S
StringReader(message)ProcessMessage(reader.ReadToEnd())reader.Close()
7 Y7 h; y, m, {* _6 N8 fB. Dim reader As New StringReader(message)While reader.Peek() -1
: M+ t/ Z: O J+ S( }2 k, uDim line as String = reader.Read().ToString()
1 |) ?, ^! }, O& | }ProcessMessage(line)End Whilereader.Close()
6 T* P: u% K7 s1 n- @$ X5 ~. ~, pC. Dim reader As New " J. {0 Y6 U; l D
StringReader(message)ProcessMessage(reader.ToString())reader.Close()
- D9 i" t2 j. K) r9 XD. Dim reader As New StringReader(message)While reader.Peek() -1
- t5 n, |* V: t% C) QProcessMessage(reader.ReadLine())End Whilereader.Close()
' H% ^3 Z' O7 S$ d9 C答案: D |