I am curious about how C# interprets/stores different data types coming from SQL Server which are then being stored in a C# string variable:
Example:
Let's say I have a variable to hold a string value retrieved from a database call:
public string TransactionId {get; set;}
Will the value in TransactionId be represented any different if:
Just wondering how these 2 different data types get stored in the C# string type. Will C# store a VARCHAR value with 8 bits and a NVARCHAR with 16?
They will be stored in the string type pretty much exactly the same. It's only difference is the UTF-16 or larger Formatting in an SQL DB will as you know take up more physical storage space in the DB. If you are using only ASCII/UTF-8 for example (Any 8-bit limited character set) you should store as varchar. the string value in C# will represent exactly the same as nvarchar and varchar are both castable to string natively. The only content difference of your string will be if extended characters are used and stored in nvarchar. These will not store in varchar.
Also just informational; var in a SQL type means the size will dynamically change depending on what content it has been given varchar(n) where n is the max size it can be. works the same with for example, varbinary(n), etc.
You can have a look here
http://msdn.microsoft.com/en-us/library/cc716729(v=vs.110).aspx
nvarchar and varchar are mapped to String
EDIT: nvarchar, varchar, ntext, text, char, nchar are all mapped to String or Char[]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With