简体   繁体   中英

transfer from java to C#

I want to transfer this part of java code to C# but I have get stucked in that:

public class PCComm {
      private SerialConnection sc;

public String systemfaults() {
  if ( (sc == null) || !sc.open) {
       return ("Serial communication not established");
       } 

   return ("OK");
  }
}

The Error for the (!sc.open) is that : Serialconnection.open is inaccessible due to its protection level

I changed the "Private" access level to "protected" level. Does it make sense ?


Edition:

I changed the code based on the comments that I got:

   public class PCComm {
          public readonly static int OPEN = 0;
          private SerialConnection sc;


   public PCComm() {
   }

    public String systemfaults() {
      if ( (sc == null) || !sc.open) {
           return ("Serial communication not established");
           } 

       return ("OK");
      }
    }

Still I get error in (sc.open)...

No, protected will not make the fields of SerialConnections available to external classes. You can either make the open field public:

public boolean open

or define a method, like this:

public boolean isOpen(){
    return this.open;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM