070-543 Free Dumps Study Materials
Question 9: You develop an add-in for Microsoft Office Excel by using Visual Studio Tools for the
Microsoft Office System (VSTO). The add-in contains a class that uses the following method.
public void ProcessCells() {
Excel.Worksheet ws = Application.ActiveSheet as
Excel.Worksheet;
List<object> values = new List<object>();
//Your code goes here
}
The add-in must retrieve the values for the cells in the range A1 through E3.
You need to exclude empty cell values when you retrieve cell values from the range.
Which code segment should you use?
A. Excel.Range rng = ws.get_Range("A1", "E3"); foreach (Excel.Range r in rng.Cells) { if (r != null)
values.Add(r.Value2); }
B. Excel.Range rng = ws.get_Range("A1", "E3"); foreach (Excel.Range r in rng.Cells) { if (r.Value2 !=
null) values.Add(r.Value2); }
C. Excel.Range rng = ws.get_Range("A1", "E3"); for (int x = 0; x < 3; x++) { for (int y = 0; y < 5; y++) {
Excel.Range r = rng.Cells[x, y] as Excel.Range; if (r.Value2 != null) values.Add(r.Value2); } }
D. Excel.Range rng = ws.get_Range("A1", "E3"); for (int x = 1; x < 4; x++) { for (int y = 1; y < 6; y++) {
Excel.Range r = rng.Cells[x, y] as Excel.Range; if (r != null) values.Add(r.Value2); } }
Correct Answer: B