473,385 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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;
  3.  
  4. GraphControl.XMLUtility<double> obj = new XMLUtility<double>();
  5.  mtrxgraphdata = obj.GetElement("//Matrix/matrixdata/",Matrixdata);
  6.  
  7.  
  8.  
  9. Here is the code for the Generic class.
  10. class XMLUtility<T>
  11.           {
  12.             public T GetElement(string Xpath,XmlDocument XmlDoc)
  13.             {
  14.  
  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;
  25.  
  26.             }
  27.          }
Thanks in advance
Jan 25 '08 #1
1 8164
rt7777
1
try this:

http://goingspare.wordpress.com/2006/10/22/generic-methods-now-theres-a-thing/

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

3
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...
4
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...
7
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....
16
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
9
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 **'"
2
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...
1
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...
7
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"> ...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.