+ 2

How can I use explicit conversion in C# as I m trying this for converting int to char...

https://code.sololearn.com/cW7x2kElnQEX/?ref=app

14th Dec 2018, 1:48 PM
Marut Nandan
Marut Nandan - avatar
4 Answers
+ 2
I don't know much about c# but i guess there is no problem in type-conversion. You are trying to use Implicitly typed as Explicitly types variables which are declare using the var keyword should have compile-time initialization in c#. What m trying to say is declaration and initialization should be in same statement. eg 1)//this is wrong var i; for(i = 1 ; i<=5 ; i++) { //do something } eg 2)//this is correct for(var i = 1 ; i<=5 ; i++) { //do something } Secondly you don't need to typecast to int as the compiler is smart enough to figure-out what type of value is getting stored //consider the following code snippet for(var i=65;i<=70;i++) { Console.Write((char)i); } output: ABCDEF
14th Dec 2018, 2:50 PM
Rishi Anand
Rishi Anand - avatar
+ 2
Updated Rishi Anand .. See code in multi-line comment..
14th Dec 2018, 1:53 PM
Marut Nandan
Marut Nandan - avatar
+ 2
It's working.... THANK YOU! Rishi Anand 😊
14th Dec 2018, 8:36 PM
Marut Nandan
Marut Nandan - avatar
0
Please post your code here
14th Dec 2018, 1:49 PM
Rishi Anand
Rishi Anand - avatar