Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
can someone tell that how to remove this error from my code my ,code is :--

C#
f = file.FileName;
if (!string.IsNullOrEmpty(f))
{
    f1 = adcode;
    f  = f.Substring(f.LastIndexOf("."));
    f1 = "~/images/" + f1 + f;


Pls some tell, on adcode, throwing an error.
Posted
Updated 22-Apr-11 23:44pm
v2
Comments
[no name] 23-Apr-11 5:34am    
Which error,
And what is datatype of f1

line cannot implicitly convert type 'int' to 'string' in asp.net c# heared so many time,

You have to do following things,

f1= Convert.ToString(abcode);

or

f1=adcode.ToString();
 
Share this answer
 
For converting to string use Convert.ToString method or ToString() method (every object has one!).
For converting from string to some numeric value use Parse or TryParse method of particular type.

For anything else, take Santosh's advice. Read MSDN about type casting.
 
Share this answer
 
Hey if abcode is integer then you should used
const int abcode= -273;
   f1 = Convert.ToString(abcode);

Please read MSDN for more information of type casting
 
Share this answer
 
What type is the variable abcode?
 
Share this answer
 
You can try

f1 = Convert.ToString(abcode);


This can be use full.

Hope this can help you.
 
Share this answer
 
I'm a fan of the String.Format method. This will take any object and call it's ToString method for you, then apply it to your specified string along with any other formatting (if you so choose).

C#
f = file.FileName; 
if (!string.IsNullOrEmpty(f)) 
{ 
    f1 = String.Format("~/images/{0}{1}", adcode, f.Substring(f.LastIndexOf(".")));
}


More info here: http://msdn.microsoft.com/en-us/library/system.string.format.aspx[^]
 
Share this answer
 
chander_rani wrote:
f = file.FileName;<br />
if (!string.IsNullOrEmpty(f))<br />
{<br />
    f1 = adcode;<br />
    f  = f.Substring(f.LastIndexOf("."));<br />
    f1 = "~/images/" + f1 + f;


I see that f is a string but on the part of f1 there is no other code to support if f1 is the integer and adcode the string or if adcode the integer and f1 the string, so the solution can go a few different ways.

if f1 is an integer and adcode is an integer then f1=adcode; is correct but f1 = "~/images/" + f1 + f; is incorrect because "/images/" cannot be converted to integer

if f1 is string and adcode is an integer then f1=adcode would be incorrect and to fix this just call as f1=adcode.ToString(); and f1 ="~/images/" + f1 + f; would display correctly.

if f1 is an integer and adcode is a string then it's all wrong. first only if adcode is equal to an integer example adcode="10"; could you call f1=adcode but it would have to be called as f1=Int32.Parse(adcode); and second f1="~/images/" + f1 + f; could not be called because "/images/" is not convertable to an integer.
 
Share this answer
 
v4
write it as f1 = "abcode"; or if abcode is an integer then use it as abcode.ToString()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900