About the underline

Hi,

What is the difference between
Word._Application word;
and
Word.Application word = new Word.Application();

When should I use which one?
johnwoodAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Todd GerbertIT ConsultantCommented:
_Application and Application are both interfaces, and at first glance it looks like _Application is just one piece of Application (that is to say, Application inherits from _Application along with some other interfaces).
The correct usage, I believe, is Word.Application word = new Word.ApplicationClass();
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
johnwoodAuthor Commented:
Thank you.

Yes, I am using
Word.Application word = new Word.Application();
Word.Document doc = word.Documents.Open(ref ....);

However, when doing doc.Close(ref miss, ref miss, ref miss); I got message:
Ambiguity between method 'Microsoft.Office.Interop.Word._Document.Close(ref object, ref object, ref object)' and non-method 'Microsoft.Office.Interop.Word.DocumentEvents2_Event.Close'. Using method group.

It seem some ambiguity between underline and without underline.....
0
Todd GerbertIT ConsultantCommented:
Word.Application word = new Word.ApplicationClass();
not
Word.Application word = new Word.Application();
 
I think it's safe to disregard that warning - it's saying the document object has a method named "Close" and an event named "Close", and the compiler is choosing to use the method named "Close"
 
0
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Todd GerbertIT ConsultantCommented:
Or,
Word._Document doc = word.Documents.Open(...)
0
johnwoodAuthor Commented:
OK, disregard that warning.

Sorry, want to know more, why you said:
Word.Application word = new Word.ApplicationClass();
not
Word.Application word = new Word.Application();

I always use
Word.Application word = new Word.Application();
or similar things for Excel and Access and didn't find any problem??
0
Todd GerbertIT ConsultantCommented:
Application is an interface, and when you instantiate it you actually get an object of type ApplicationClass (which implements Application). Probably six of one, half dozen of another, I just saw ApplicationClass used in a Microsoft example when I was first learning so that's what I stuck with.
 
0
johnwoodAuthor Commented:
Thank you.
0
Todd GerbertIT ConsultantCommented:
Silly example, and not directly related to your question, but maybe interesting nonetheless.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
	public interface ITest
	{
		string Message { get; }
	}

	[CoClass(typeof(TestClass2)), ComImport, Guid("75578300-2CB7-4142-98F4-3CBC7F0BF504")]
	public interface ITest2
	{
		string Message { get; }
	}

	public class TestClass : ITest
	{
		public string Message { get { return "Hello World"; } }
	}

	public class TestClass2 : ITest2
	{
		public string Message { get { return "Hello World2"; } }
	}

	class Program
	{
		static void Main(string[] args)
		{
			//ITest a = new ITest(); // Fails, can't instantiate an interface
			ITest b = new TestClass(); // Works, TestClass implements the interface ITest
			ITest2 c = new ITest2(); // Works, because CoClass attribute of ITest2 says to actually return a TestClass2
			ITest2 d = new TestClass2(); // Effectively same as above line

			//Console.WriteLine("a is of type: {0}", a.GetType().Name);
			Console.WriteLine("b is of type: {0}", b.GetType().Name);
			Console.WriteLine("c is of type: {0}", c.GetType().Name);
			Console.WriteLine("d is of type: {0}", d.GetType().Name);

			Console.ReadKey();
		}
	}
}

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.