How to translate My.Application.Info.AssemblyName from VB?

S

Siegfried Heintze

Can someone kindly translate the following line from VB.NET to C#?
Thanks!
Siegfried

outp.WriteLine("starting " & My.Application.Info.AssemblyName & "/Module1.vb
clr=" & Environment.Version.ToString & " os=" & My.Computer.Info.OSPlatform &
"v" & My.Computer.Info.OSVersion.ToString)
 
R

Roger Frost

Siegfried Heintze said:
Can someone kindly translate the following line from VB.NET to C#?
Thanks!
Siegfried

outp.WriteLine("starting " & My.Application.Info.AssemblyName &
"/Module1.vb
clr=" & Environment.Version.ToString & " os=" &
My.Computer.Info.OSPlatform &
"v" & My.Computer.Info.OSVersion.ToString)

Give a man a fish...

Console.WriteLine("starting " +
this.GetType().Assembly.GetName().Name.ToString() + " /Module1.vb clr=" +
Environment.Version.ToString() + " os=" +
Environment.OSVersion.Platform.ToString() + " v=" +
Environment.OSVersion.ToString());

Personally, I would use something more like...

Console.WriteLine("starting " +
this.GetType().Assembly.GetName().Name.ToString() + " /Module1.vb clr=" +
Environment.Version.ToString() + " os=" + Environment.OSVersion.ToString());

....Because Environment.OSVersion.Platform.ToString() is redundant in what
you are trying to produce (I think)

....and maybe Module1.vb should now be the name of a .cs file?

Or teach a man to fish...

You can also access the VB My namespace from C# as explained here:

http://www.petermorano.com/Leveraging-VB-MyNamespace-From-CSharp.aspx

if you like using it for these types of statements, trust me I know these
translations can be a little confusing at times.

Roger Frost
"Logic Is Syntax Independent"
 
S

Siegfried Heintze

(1) If I'm in a static function, is there a better way to get the class than
new? Here is my code:

public static void Main(string[] args){
try{
outp.WriteLine("starting " +
new test().GetType().Assembly.GetName().Name.ToString() + " /test.cs
clr=" +
Environment.Version.ToString() + " os=" +
Environment.OSVersion.Platform.ToString() + " v=" +
Environment.OSVersion.ToString());
(2) I ran this program first under Visual Studio 2005 and received v2 for
the CLR version. I ran it again under Visual Studio 2008 and still received
v2 for the CLR.
(a) Should not there be a new version of the CLR for VS 2008?
(b) How do I get the version of the C# compiler?

Thanks,
Siegfried
 
J

Jeroen Mostert

Siegfried said:
(1) If I'm in a static function, is there a better way to get the class than
new? Here is my code:

public static void Main(string[] args){
try{
outp.WriteLine("starting " +
new test().GetType().Assembly.GetName().Name.ToString() + " /test.cs
clr=" +

Use typeof(test) instead of new test().GetType().
Environment.Version.ToString() + " os=" +
Environment.OSVersion.Platform.ToString() + " v=" +
Environment.OSVersion.ToString());
(2) I ran this program first under Visual Studio 2005 and received v2 for
the CLR version. I ran it again under Visual Studio 2008 and still received
v2 for the CLR.
(a) Should not there be a new version of the CLR for VS 2008?

No. The latest version of the CLR is v2. You're confused with the .NET
framework version number. Version 3.0 and 3.5 of the framework still run on
CLR version 2.
(b) How do I get the version of the C# compiler?
You can't. No such information is recorded in the assembly.

Do you have any specific information you're after? In general applications
don't know and shouldn't care about details like these, only if their
prerequisites are available (which should be handled by the installation).
 
S

Siegfried Heintze

No. The latest version of the CLR is v2. You're confused with the .NET
framework version number. Version 3.0 and 3.5 of the framework still run on
CLR version 2.

You can't. No such information is recorded in the assembly.

Ah hah! What is the function call to retrieve the value 3.5 that represents
the framework version number?
Do you have any specific information you're after? In general applications
don't know and shouldn't care about details like these, only if their
prerequisites are available (which should be handled by the installation).

I'm writing some tutorial programs and would like to confirm a correlation
between the features I'm demonstrating and the version number.

Thanks,
Siegfried
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top