Click here to Skip to main content
15,912,897 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
in a c# solution when we add different projects.I have two questions :
1) why we give reference to the other project? can't we just use inheritance???
2) After we give the reference by using the visual studio IDE why we have to add the project to the namespace system??? for example: using blog.entity; i thought that much intelligent IDE would do that.

thanks in advance for your replies that informs and enlighten.
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Blog.Entity;
using System.Data.SqlClient;
using System.Data;
Posted
Updated 9-Jul-12 1:00am
v2

1 solution

Becaue you aren't ingheriting anything by default.
Adding a reference tells VS that you want to refer to classes within the DLL - either by instantiation them:
C#
MyDLLClass instance = new MyDLLClass();
Or by using the static methods:
C#
string myString = MyDLLClass.StaticMethod();
In addition, you can use these classes as a basis for your ouwn classes via inheritance:
C#
public partial class MyClass : MyDLLClass
   {
   ...
But just because you can reference a class within a DLL file, doesn't mean that you want to in every file: the using namespace statemkent just lets VS accept a shortcut: instead of having to type
C#
string s = MyDLLNamepace.MyDLLCLass.StaticMethod();
each time, you can just type the shorter version:
C#
string s = MyDLLCLass.StaticMethod();
But you might not want that in every file - what if you have MyDLLClass in two DLL files, under different namespaces? If it added a using to every file automatically when you added a reference, then any existing uses would have a problem trying to work out which version you meant to write.
 
Share this answer
 
Comments
y.baris 9-Jul-12 8:16am    
Thanks OriginalGriff nobody can explain better ...
OriginalGriff 9-Jul-12 8:21am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900