I'm thinking something where the following two are equivalent:
int [] array = { 1,2,3,4 }
foreach( int i in array ) {
print i
}
array = { 1,2,3,4 }
foreach( i in array ) {
print i
}
Yes, languages that have type inference work this way. The code is statically typed, but the compiler can figure out that if you write { 1,2,3,4 }, then anything you assign that to, or call with that, is of type int[]. It saves a lot of (finger) typing.
C# allows you to use the var keyword in declarations to infer the type from the right hand side of the assignment.
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