Difference between namespace in C# and package in Java

前端 未结 6 526
日久生厌
日久生厌 2020-11-28 20:32

What is the difference (in terms of use) between namespaces in C# and packages in Java?

6条回答
  •  萌比男神i
    2020-11-28 21:14

    A namespace is just like a new folder, all subfolders are sub-namespaces. If we consider a namespace as a function like we have a namespace advertising under marketing namespace then we use marketing.advertising.adsclass.adsmethod. Very easy to solve a problem. Java has same method via package but complex for new comers.

    In C#

    ''' namespace marketing{

               class admissions{
                         int admissions_method(){
                         }
               }
         namespace advertising{
               class  advertisement{
                        void ad_in_newspaper( int no_of_lines){
                        }
                        void ad_on_tv(int seconds){
                        }
    
         }
    

    }

    To use in client class

    using marketing;
    using marketing.advertising;
    

    ''' In java you use same method. You pack multiple classes in one package and use it many times. It increases uniqueness. You write once and use many times. Related classes in one package. No need to code many times.

提交回复
热议问题