Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello,

I have a code written in Visual Basic and I am writing the same in C# now.

The code in Visual Basic is as follows:

VB
<pre>Dim Width1500 As String = fPath + "\err\Width1500\" & i1.value


When I tried to write the same in C#, it showed me an error. The code I wrote is:

C#
string Width1500 = fPath.ToString() + "\\err\\Width1500\\" + i1.value;


The error I am getting is:
Error CS1061: 'object' does not contain a definition for 'value' and no extension method 'value' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

Please help.

Regards
Aman Chaurasia

What I have tried:

string Width1500 = fPath.ToString() + "\\err\\Width1500\\" + i1.value;
, but it won't help.
Posted
Updated 28-May-18 19:32pm
Comments
F-ES Sitecore 29-May-18 4:34am    
How are you assigning a value to i1?

1 solution

you have to cast the object to proper type fist(to the object type of i1)

try
(i1 as 'i1_object_type').value
 
Share this answer
 
Comments
Primo Chalice 29-May-18 1:38am    
I tried (i1 as object).value because I am running a foreach loop, a few lines before this as follows. Also, it shows me the same error as before.

foreach (var i1 in Regex.Matches(LargeImageList, "(.+\\.jpg)")). So, i believe I will have to write i1 as object itself, right?
Jinto Jacob 29-May-18 2:06am    
what is the datatype of LargeImageList. if it is a collection of string you don't need to take .value.

check types of LargeImageList and i1 and replay
Richard Deeming 31-May-18 13:39pm    
If i1 is always the expected type, then just cast it directly to that type.

If i1 is not always the expected type, then as will return null, and your code will throw a NullReferenceException.

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