3

Hi will write a dll in c# with not without namespace.

I'll write a class then converting it to dll, i.e c# default library type is

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace temp { public class c1 { public static string f1(string deger) { return deger.ToUpper() + " 333 "; } } } 

now I will write this code so :

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; public class c1 { public static string f1(string deger) { return deger.ToUpper() + " 333 "; } } 

is that twou codes are same on runtime

4
  • 8
    I suggest you read the manual... Commented Aug 11, 2014 at 7:27
  • @Sayse but you could probably say that to 90% of questions on here! Commented Aug 11, 2014 at 7:59
  • possible duplicate of What namespace are my classes in when I don't put a namespace? Commented Aug 11, 2014 at 8:00
  • @weston - I do a lot of the time, in this instance an answer would be far too broad for stack overflows format, hence the link Commented Aug 11, 2014 at 8:00

2 Answers 2

2

Then this class will be at .NET unnamed global namespace(not in assembly root namespace). And it can be accessed from anywhere as "global::c1" or just "c1"

Sign up to request clarification or add additional context in comments.

2 Comments

I updated my code and added public statement to left of class name in namspace(i forgot public statement at asking),this twou codes are same but first code have namspace {...},the difference is : this class will be at .NET unnamed global namespace(not in assembly root namespace).really ?
ok.I not use namespace alias and I convert this code to dll,can i acces from other projects to this class when not referencing this dll.So I think i can access this class from only in my dll where ı will use it in my dll, is'nt it?
2

By convert this code to dll I think you mean to compile as a library. The namespace (or lack of) has no special effect in this regard.

If you want to reference this class without referencing the dll you will need to load the dll dynamically.

Example:

Assembly a = Assembly.LoadFrom("mylibrary.dll"); 

Your next problem is to reflect and use the class. Usually you would have a library that defines some interface or interfaces.

InterfaceLibrary.dll Contains interface IC1

PluginLibrary.dll Contains class C1 which implements IC1

Program.exe

Both the Program and the plugin library refer to the interface library. The program can dynamically load PluginLibrary and look for classes that implement IC1.

Here is a more in-depth example of a plugin architecture in C#: https://stackoverflow.com/a/829828/360211

8 Comments

Sorry,my caste was with (...can i acces from other projects to this class when not referencing this dll) that: if this class addes .net's libraries or other where. i think this class addes only my dll.No other application ronning on machine con not access this class,isn't it?
No, no other application can access the class. The global namespace is not that global.
Thanks,last qustion,So if i use this dll in a project or other where i can access this class (using dll is the only way to acces this class) if i not use this dll,I can't access this class in no way,isn't it?
You can use the class if you load the assembly dynamically in the way I explained in the answer.
that mean,if i will access this class i must using that dll anywise
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.