I am in the process to rename the namespace in our project. I found a strange thing and cannot understand why is that?
Original structure:
namespace Mycompany.Util
{
public class Util{
public static void ReadDictionaryFile()
{
}
}
}
in another file
using MyCompany.Util;
namespace Logging {
public class Log {
public void MethodB() {
...
Util.ReadDictionaryFile();
...
}
}
}
above works fine, no compile error.
Then I change the Logging namespace to MyCompany.Logging, I get error in MethodB immediately telling me
"Error 5 The type or namespace name 'ReadDictionaryFile' does not exist in the namespace 'MyCompany.Util' (are you missing an assembly reference?) C:\workspace\SystemSoftware\SystemSoftware\src\log\Log.cs 283 61 SystemSoftware
"
I have to change that function call from Util.ReadDictionaryFile()
to MyCompany.Util.Util.ReadDictionaryFile()
I don't know why? Is there another Util class in the system library?
The entire using lines are followed:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using MyCompany.Util;
Edit:
In C#, when we call a static method, we have to call like this: namespace.classname.methodname
?
Ok, I just come from Java. In Java, after you use import MyCompany.Util.*;
you can call static method with this format: className.methodName;
, no package name is required.
Edit2:
C# and Java are the same, className.methodName;
is enough to call static method if we use namespace correctly.