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

Selçuklu Ebrar
  • 2,059
  • 3
  • 14
  • 11
  • 8
    I suggest you read [the manual](http://msdn.microsoft.com/en-gb/library/z2kcy19k.aspx)... – Sayse Aug 11 '14 at 07:27
  • @Sayse but you could probably say that to 90% of questions on here! – weston Aug 11 '14 at 07:59
  • possible duplicate of [What namespace are my classes in when I don't put a namespace?](http://stackoverflow.com/questions/715398/what-namespace-are-my-classes-in-when-i-dont-put-a-namespace) – weston Aug 11 '14 at 08: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 – Sayse Aug 11 '14 at 08:00

2 Answers2

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"

rufanov
  • 3,266
  • 1
  • 23
  • 41
  • 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 ? – Selçuklu Ebrar Aug 11 '14 at 07:40
  • 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? – Selçuklu Ebrar Aug 11 '14 at 07:58
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

Community
  • 1
  • 1
weston
  • 54,145
  • 21
  • 145
  • 203
  • 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? – Selçuklu Ebrar Aug 11 '14 at 08:22
  • No, no other application can access the class. The global namespace is not that global. – weston Aug 11 '14 at 08:29
  • 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? – Selçuklu Ebrar Aug 11 '14 at 08:35
  • You can use the class if you load the assembly dynamically in the way I explained in the answer. – weston Aug 11 '14 at 08:36
  • that mean,if i will access this class i must using that dll anywise – Selçuklu Ebrar Aug 11 '14 at 08:38
  • sorry,if i will access my class, i must use that dll i.e adding refference or assembly or other way. – Selçuklu Ebrar Aug 11 '14 at 08:41
  • Yes, you must reference the dll in some way. – weston Aug 11 '14 at 08:42
  • Thank for your commands,I wanted to be sure,I'm sorry to take your time. – Selçuklu Ebrar Aug 11 '14 at 08:44