سؤال

In VB.Net, I can retrieve my application's ProductName and CompanyName by using:

My.Application.Info.ProductName
My.Application.Info.CompanyName

How do I do the same thing in C#?

هل كانت مفيدة؟

المحلول

You can use Assembly and FileVersionInfo

Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
var companyName = fvi.CompanyName;
var productNAme = fvi.ProductName;
var productVersion = fvi.ProductVersion;

نصائح أخرى

Just use:

System.Windows.Forms.Application.ProductName
System.Windows.Forms.Application.CompanyName

...in assembly System.Windows.Forms.dll

Or if you prefer:

using System.Windows.Forms;
//...
string productName = Application.ProductName;
string companyName = Application.CompanyName;

You need to reference the Microsoft.VisualBasic.MyServices namespace. See this for more info. You can't use the exact same syntax though. There are also more general .net ways that you would normally use in c# to get the same kind of info you get from My.Whatever in VB but they are completely unrelated to each other. There is no direct equivalent of using My.Whatever in c# the language.

var company = new AssemblyInfo(Assembly.GetExecutingAssembly()).CompanyName;

Second usage:

var codedBy = var company = "Coded by "+(new AssemblyInfo(Assembly.GetExecutingAssembly()).CompanyName);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top