C# Excel refactoring code gives different result

deleyd
deleyd used Ask the Experts™
on
Starting with a string representing a range:
string sortRange = "C10:H24";

Open in new window

This then works:
worksheet.Range[sortRange].Sort(worksheet.Range[sortRange].Columns[1], xlSortOder.xlDescending);

Open in new window

I saw worksheet.Range[sortRange] was listed twice, so I decided to refactor that out:
Excel.Range r = worksheet.Range[sortRange];
Excel.Range c = r.Columns[1];
r.Sort(c, xlSortOrder.xlDescending);

Open in new window

My refactored version gives a much different result. Why is that?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Developer
Commented:
Just try it step by step: Thus what does

Excel.Range r = worksheet.Range[sortRange];
r.Sort(r.Columns[1], xlSortOder.xlDescending);

Open in new window

return as result?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial