Showing posts with label explain. Show all posts
Showing posts with label explain. Show all posts

Wednesday, March 28, 2012

string.Format w/ const string

Could someone please explain why this is happening. I am using ASP.NET 1.1

I have a class called PaymentMessages, it contains a few public const string(s)

publicconststring SYS_NON_SUCCESS_MESSAGE_FORMAT_STRING = "{0}: AMOUNT: {1}, RETURN CODE: {2}";

when I call string.Format(PaymentMessages.SYS_NON_SUCCESS_MESSAGE_FORMAT_STRING, "FAIL", 550.00m, "22-e")
it throws an exception because PaymentMessages.SYS_NON_SUCCESS_MESSAGE_FORMAT_STRING evaluated to null. Why is this happening on const strings?

WORKS FINE:
string s = PaymentMessages.SYS_NON_SUCCESS_MESSAGE_FORMAT_STRING;
string.Format(s, "FAIL", 550.00m, "22-e")

Hi..

Here you are trying to manipulate const variable which is not possibe. Constants can only be value types rather than reference types.

If you want manipulate that string with out creating new string u can use static readonly which is both reference type and value type.

public static readonlystring SYS_NON_SUCCESS_MESSAGE_FORMAT_STRING = "{0}: AMOUNT: {1}, RETURN CODE: {2}";

Cheers

Thursday, March 22, 2012

Strongly-Typed

Hi Folks,

Can someone please explain for me the term:Strongly-Typed please?

I recently heard about it a lot of times.

thanks in advance,

http://en.wikipedia.org/wiki/Strong_typing

Thanks, but it's too general for me.

I need maybe some example please.

Thank You.


ok. Look at this nice example

Strong vs. Weak typing

The division to strong and weak typed languages is much less clear-cut than static vs. dynamic, and there is a lot of confusion on what strong typing means. One common definition isdisallowing operations on incompatible types. Consider the following example from Perl (a weakly typed language):

print "2" + 4;

This code will print '6�� although it seemingly performs addition on incompatible types. This is because Perl is performing an implicit conversion when it sees we want to add a string that represents a number to another number. On the other hand, Ruby is strongly typed and the above statement will generate aTypeError.

More info:http://eli.thegreenplace.net/2006/11/25/a-taxonomy-of-typing-systems/


Ok...

I get something.

Thanks a lot.