Same Class Name

bbkevin used Ask the Experts™
Hi Experts,

I have the WebSite, which contains the following class in the App_Code folder.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Mail;

/// <summary>
/// Summary description for Web
/// </summary>
public class Attachment
    public Attachment()
		// TODO: Add constructor logic here

        // The implementation is omitted


Open in new window

I need to employ methods in the System.Web.Mail.Attachment class in order to send mail.
Now I recognize that my Attachment class name conflict with System.Web.Mail.Attachment class.
If I create a Attachment class (used for my Database Model / Entity), is there any conflict / issues?
If yes, what is the common prefix for the Entity?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Add Namespace to resolve issues if any
ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Read my comment in another question as to why we use namespaces.
Navneet.Net Full Stack Developer

Yes, Namespace is like a Unique Path  to Your Class.
Hence if you have two then there is Conflict, but natural.

So it has to be unique

Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.


ASP.NET Web Site, not a Web Application
It is possible to add namespace?
.Net Full Stack Developer

1) Namespace is common to .Net, Irrespective of  Project Type.
2) As I Say Namespace is unique
Hence  System.Web.Mail.Attachment here Attachment Class comes from System.Web.Mail Namespace
For you Just have Unique Namespace
MyApplication.Attachment .Mail

3) Common prefix for Entity is Model



Thanks for help!
I used namespace to make my class unique.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial