472,796 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,796 software developers and data experts.

Problem with Typecast in Generic class "Cannot convert type 'string' to 'T' "

Hi All,
I am facing the problem in Typecast inside the Generic class.
I need a function which will take two param 1:-Xpath 2:- XMLDOC
and return me what i will need.

here is the code for accessing to the Generic class.

Expand|Select|Wrap|Line Numbers
  1. private double mtrxgraphdata;
  2. private XMLdocument Matrixdata;
  4. GraphControl.XMLUtility<double> obj = new XMLUtility<double>();
  5.  mtrxgraphdata = obj.GetElement("//Matrix/matrixdata/",Matrixdata);
  9. Here is the code for the Generic class.
  10. class XMLUtility<T>
  11.           {
  12.             public T GetElement(string Xpath,XmlDocument XmlDoc)
  13.             {
  15.                 XmlNodeList Elements = XmlDoc.SelectNodes(Xpath);
  16.                 T[] returnList = new T[Elements.Count];
  17.                     int counter = 0;
  18.                     foreach (XmlNode node in Elements)
  19.                     {
  20.                         returnList[counter] =(T) node.InnerText;// here i am getting  error  "Cannot convert type 'string' to 'T' "
  21.                         counter++;
  22.                     }
  23.                 }
  24.                 return returnList;
  26.             }
  27.          }
Thanks in advance
Jan 25 '08 #1
1 8118
try this:


especially: attValue = (T)Convert.ChangeType(strVal, typeof(T));
Feb 21 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

by: H. S. | last post by:
Hi, I am trying to compile these set of C++ files and trying out class inheritence and function pointers. Can anybody shed some light why my compiler is not compiling them and where I am going...
by: kishor | last post by:
I have an activeX dll, I am calling one function from that dll. I am using C# as coding language. I am getting following error. cannot convert from 'string' to 'ref string' How do I call this...
by: Assimalyst | last post by:
Hi, I am trying to write some server side validator code in C#. I want to have a piece of code that can be used by all DropDownLists on a webform, giving a false value if the SelectedIndex is 0....
by: ondekoza | last post by:
Hello, I need to convert the string "FFFFFFFF" to a long. To convert this string I tried the following: >>> 0xffffffff -1 >>> 0xffffffffL 4294967295L OK, this is what I want, so I tried
by: Igor Okulist | last post by:
int func(void**); { short* p = NULL; func(&p); //<<< here } Could somebody remind me why is this not allowed ? error message: "cannot convert parameter from 'short **' to 'void **'"
by: keithb | last post by:
A web site published from its development environment (VS Web Server) to an IIS 6.0 site displays this message: Compiler Error Message: CS0030: Cannot convert type 'ASP.login_aspx' to...
by: stillh2os | last post by:
Hello. I'm new to .NET, and I'm trying to implement a callback function. I want my managed C++ code to call an unmanaged function, passing in a callback function that the unmanaged C/C++ code...
by: preeti13 | last post by:
i have a java script function with the pop up i want to update a database ow i am getting the erorr any one please help me with this. code is like this <script type="text/javascript"> ...
by: nomad | last post by:
Hi, When trying to serialize a class I keep getting the message below. optionalExtensionTypeOptionalExtension is not mandatory so not sure why this is appearing. If anyone has seen this type...
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: Mushico | last post by:
How to calculate date of retirement from date of birth
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.