-1

While looking for an example how to open an Excel file with Excel Interop I stumbled upon this answer where the author writes the following under a piece of code that uses the Workbooks.Open method:

[..], this stuff is much easier if you use VB.NET. [..]. VB.NET does option parameters well, C# does not, hence the Type.Missing.

I compared this method in VB.NET and C# in a solution with two projects and they are identical. Do I miss something or is it correct that they have the same signature with a bunch of Object typed parameters?

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
t3chb0t
  • 16,340
  • 13
  • 78
  • 118
  • 1
    That post is from 2009 (pre-historic c#). C# has optional parameters and `dynamic` to help with interop-ing. – Crowcoder Oct 21 '22 at 19:39
  • 1
    That answer is from 2009, though one of the comments has a broken link to what I think is [this blog post](https://blogs.iis.net/samng/com-interop-in-c-4-0), also from 2009, explaining some of the improvements to working with COM even in C# 4.0. That includes not having to repeatedly pass `Type.Missing` parameters. – Lance U. Matthews Oct 21 '22 at 19:42
  • It depends on personal preference. Both VB.NET and C# compile into IL code, so code written in either one to do a task will look basically identical once compiled. So no, one is not "better" than the other, and "easier" is a relative term. It depends on which language you're more comfortable with. – Jesse Oct 21 '22 at 19:42
  • @Crowcoder are you saying that the ancient C# was using `dynamic` types where VB.NET put `Object` like they now both do? – t3chb0t Oct 21 '22 at 19:42
  • 1
    No, I'm saying modern c# has `dynamic` – Crowcoder Oct 21 '22 at 19:46
  • 1
    VB.Net already had looser typing with its `Object` doing what C# `dynamic` eventually did, roughly. It was a consequence of `Object` replacing both VB6 `Object` and `Variant` types at the same time - the latter was already doing what today's `dynamic` does, but back in the '90s. – djv Oct 21 '22 at 20:28
  • 1
    The original iteration of C# lacked `dynamic` and it lacked optional parameters. Both decisions were consistent with the philosophy of the language, but they made it painful to do Office interop because of the design of the Office interfaces (which rely heavily on dynamic typing / late binding and frequently use optional parameters). – Craig Oct 24 '22 at 14:03

1 Answers1

3

There is no big difference between the two because they are used to generate the IL code. Only the difference in the generated IL code makes any sense. They both provide almost the same language features and don't have so much better nuances. If you are familiar with one of them go with it and don't listen to anybody. Both programming languages are popular for automating Office applications. VB.NET is very convenient to chose who migrates Office solutions written in VBA, C# is popular between other .Net developers who requires automating Office or creating a COM add-in.

I personally used both programming languages a lot for Office solutions and didn't find any valuable pros and cons. Both are valid.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45