So I started learning C# on Monday morning, I have spent the past two days watching video after video and now I have a few observations that I want to know if I am thinking about correctly.
My past is about ~4 years of college-level Java programming, so if any explanations are called for and referring it to a Java item is relevant, please feel free to make a mindset link to it.
I am also starting my first "real" application development internship, so they are having me learn stuff the first week on my own before I start working on C# and .Net based projects.
The "as" operator: From my understanding this is basically a cast. So I could say
int a;
double b;
a as b;
and this should be equivalent to (double)a, correct?
or
object sender;
Label clickedLabel = sender as Label.
This will then be like (Label)sender, with sender being an object but now casted as a label, correct?
dynamic type: My understanding of this, is that it is a "all the things!" type, meaning that dynamic d; could be used as an int, double, object, string, ect.. it can apply to anything. Yes/no/kind of?
dynamic d =5;
int a = d;
string b = d;
object c = d;
If that is correct, how is this different from boxing? Is boxing just an "as" operator/dynamic type but ONLY for use with the type Object?
Integer Literals, how often are these used and in what scenarios? I watched a segment on them and they seen pretty strange. I will be doing application development so if these are useful please explain some of their everyday purposes please
212 = decimal
215 = decimal unsigned
0xFccL = long hexidecimal (i think)
058 = Illegal as 8 is not an octal digit
05UU = Illegal as a suffix (the u for unsigned) is repeated
30u1 = unsigned long
30u = unsigned int
I am just confused as to where these would all be used for an application development type. They seen more like direct assembly interaction to me, but maybe that is a common part of app dev stuff (first "real" internship)
{#} syntax / WriteLine: So I have made a few demo apps and they use a syntax like..
Console.WriteLine("Radius: {0}, Area: {1}", r, areaCircle);
or
Console.WriteLine("{0}:{1}:{2}", e.Hour.ToString(), e.Minute.ToString(), e.Second.ToString());
From what I am realizing, the {0}, {1}, {2}, ect.. somehow are pulling values out of sets (that I do not think I physically created).
I am unsure what this is "called" so I do not know how to Google for it.
Would someone mind pointing me in the right direction as I find this to be a very useful operation.
Nullable Types: From what I have learned here is that an expression such as
static int? d;
if (d.HasValue)
{
// something
}
would not throw any errors as it would be a valid interaction, while in Java this would cause some kind of compile error.
I believe you can also set a nullable type with an instantiation to begin with, such as:
int? d = 5;
Which would be the same as above but as a null attribute tagged to it.
My question about this is,
Can "Nullable" be applied to all Types or only some?
Could you have an actual value for d, but still make a check return null? Since you can tag on a null attribute to a type, I am guessing that the attribute of "null" and the "value" itself are treated/checked independently of each other. Is that a correct or incorrect guess? (I can try to explain better if need be)
string questions!
Do we used string in C# as we would use String in Java? (capitalization)
When using substring, why do these two strings return different answers?
string sub = input.Substring(0, 3); //returns index 0-2
string sub = input.Substring(3, 3); //returns index 3-6
May add more...
Hopefully this is not asking too much, I am just trying to make sure I learn C# as best as I can over the next few days.
If any of you know some good articles/tutorials/ect on C# in terms of what a new app dev should know, please point me in that direction. I have a PluralSight account as well so you may direct me to their tutorials too.
Thank you,
-Austin