Вопрос

I am trying to convert simple vba "with statemnt" to C#. ProductRangeA and B are named ranges. Could someone to give a hint?

With ProductRangeA
   myRow= .Rows.Count: 
   myValue= .Value  
End With

With ProductRangeB
   myRow= .Columns.Count: 
   myValue= .Value  
End With
Это было полезно?

Решение

As HighCore said, there's no C# equivalent to VB's With block. Here's the equivalent C# code:

myRow = ProductRangeA.Rows.Count;
myValue = ProductRangeA.Value;

myRow = ProductRangeB.Columns.Count;
myValue = ProductRangeB.Value;

Since you can't avoid typing ProductRangeA and ProductRangeB twice each, you can reduce typing by using shorter variable names. That can make the code more difficult to understand, of course.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top