internal class access c# -


this maybe simple question! have been scratching head hour now! have 2 files below:

  1. assembly1.cs
  2. program.cs

i thought when use internal keyword before class name won't able instantiate in other classes, right?

https://msdn.microsoft.com/en-us/library/7c5ka91b.aspx

but why not getting error message here? maybe missing obvious here.

// assembly1.cs namespace internaltest {     internal sealed class baseclass      {         public static int intm = 0;     } }   // program.cs using system;  namespace internaltest {     class program     {         static void main(string[] args)         {              var mybase = new baseclass();              console.readkey();          }     } } 

internal means class accessible within assembly.above class in same assembly hence no error.if want see error follow below step

1) create library project

2) create base class in project

3) create console project

4) add reference of first project dll

5) try create instance, see error

additional info

if want access internal members in console project add below attribute in assemblyinfo.cs of library project

[assembly:internalsvisibleto("[assemblynameofconsoleproject]")]  

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -