0

How i can create const variable

How can i do something like that: int x = 10; const int y = x; https://code.sololearn.com/c7lGVHMiSiYK/?ref=app

19th Dec 2019, 6:40 AM
Fox~
Fox~ - avatar
19 Answers
+ 5
Just use "const int x = 10;" in the first line.
19th Dec 2019, 7:13 AM
Sonic
Sonic - avatar
+ 5
Alternatively use "const int y = 10;" in the second line.
19th Dec 2019, 7:14 AM
Sonic
Sonic - avatar
+ 2
Constants only accepts another constant or literal in initialization. Your <x> is non constant, that's why <y> is not getting initialized. https://www.c-sharpcorner.com/UploadFile/2072a9/constant-vs-readonly-vs-static-keywords-in-C-Sharp/
19th Dec 2019, 7:19 AM
Ipang
+ 2
I have a method DllImport which take only const string variable, but first i need get this string. So I need something like a constant.
19th Dec 2019, 7:23 AM
Fox~
Fox~ - avatar
+ 2
I added link to example code
19th Dec 2019, 7:50 AM
Fox~
Fox~ - avatar
+ 2
Well, what did you expect? DLL are library files for Windows O/S. You probably could try to run the code on Visual Studio under Windows.
23rd Dec 2019, 6:03 AM
Ipang
+ 1
Share your code link in the original question Description (above) so the problem can be understood more obviously. At the moment anyone can only play guesses until your code is here for a review. Follow this guide on sharing links in case you didn't know just yet https://www.sololearn.com/post/74857/?ref=app
19th Dec 2019, 7:39 AM
Ipang
+ 1
Sorry, but it doesn't look like a valid way of dynamic linking to DLL (no DLL file was specified). Please check if that was really how it should be done, search for DllImport specifics on the net 👍
19th Dec 2019, 7:54 AM
Ipang
+ 1
Have a look at the link below. https://stackoverflow.com/questions/8859060/c-sharp-using-const-with-dllimport It seems you do not need to make it a const. What happens if you use a regular string variable ?
19th Dec 2019, 8:25 AM
sneeze
sneeze - avatar
+ 1
Dll on c++
20th Dec 2019, 4:03 AM
Fox~
Fox~ - avatar
+ 1
ok so I understand. It is not about the calling a function in the dll. It is about loading the dll in with DllImport. Is it the path that is dynamic or the name of the .dll as well ? Have a look at the link below. https://stackoverflow.com/questions/8836093/how-can-i-specify-a-dllimport-path-at-runtime or can you use loadlibrary https://dev.to/jeikabu/loading-native-libraries-in-c-fh6
20th Dec 2019, 9:32 PM
sneeze
sneeze - avatar
0
DllImport is used to initialize a dll with unmanaged code, which is located in the project folder, to which you first need to know the path and then use it. I don't found another way to do this.
19th Dec 2019, 8:01 AM
Fox~
Fox~ - avatar
0
It's not what i need. I talk about it: string x = "address"; [DllImport(x)] //Error: first argument must be a const variable
19th Dec 2019, 8:36 AM
Fox~
Fox~ - avatar
0
What is the language the dll was written in ?
19th Dec 2019, 4:34 PM
sneeze
sneeze - avatar
0
Const variable - this is an oxymoron :)
20th Dec 2019, 8:00 PM
andrze
andrze - avatar
0
It's don't work on android :/
23rd Dec 2019, 5:24 AM
Fox~
Fox~ - avatar
0
Dll can be compiled for android, but now the main question is not, I need to somehow open this dll
24th Dec 2019, 1:27 PM
Fox~
Fox~ - avatar
0
Really, DLL can be compiled for Android? Well good luck with trying
24th Dec 2019, 7:16 PM
Ipang
0
But why VS compiled dll file first, and then, compiling apk file?
24th Dec 2019, 8:51 PM
Fox~
Fox~ - avatar