How to change final property from Java to C #?

2

What property in C # is corresponding to final of Java, I need to change my variables final String mensagem = "Tokio Marine Seguradora S.A."; to something corresponding in C #.

using System;

namespace ConsoleApplication
{
    public sealed class Criptografia
    {
        private static readonly String ALGORITMO = "AES";

        public static String descriptografar(String mensagem, String chave) 
        {

          //  final Cipher cipher = getCipher(Cipher.DECRYPT_MODE, chave);

          //  final byte[]
          //  descriptografado = cipher.doFinal(Base64.decodeBase64(mensagem));

                //return new String(descriptografado, "UTF-8");

            return "";
        }

        public static void Main(string[] args)
        {
            // Mensagem que sera criptografada.
            final String mensagem = "Tokio Marine Seguradora S.A.";

            // Senha definida da operadora.
            final String chave = "JessicaBiel";

            //// Valor criptografado.
            //String criptografado = Criptografia.criptografar(mensagem, chave);
            //Console.Write("Valor criptografado: '%s' %n", criptografado);

            //// Valor original.
            //String descriptografado = Criptografia.descriptografar(criptografado, chave);
            //Console.Write("Valor descriptografado: '%s'", descriptografado);

            Console.ReadKey();
        }
    }
}
    
asked by anonymous 09.09.2016 / 19:58

1 answer

4

In the context of the question is const , but in fact it is not usually useful and I have practically never seen it being used. "Constants" within a local scope helps very little.

And its use is weird because it's not actually constant, it's just an immutable variable (the correct one should be readonly .

And not everyone understands what const actually does. With some types it will not work as the person expects and there may be changes to the same object using the modifier (the correct name of this).

Other contexts

In class or instance variables is readonly .

If it were in a class, the equivalent would be sealed .

In methods the default C # method is not virtual, so do not need it. Unless you wanted to prevent virtuality in a tree where the method was already virtual, then the use must be sealed also, with override .

Extra

Ideally it would be good to convert idiomatically. It's weird to have a Java style in C # code. And it's easy to end up making a mistake for that.

See more: What is the difference between const and readonly?

    
09.09.2016 / 20:00