1

I have a text file with the following:

int A = 5 ;
string str = "tempstring" ;
str DosomeMethod 15 16 20 22 ;

When reading the text file thru my program, I want to declare int A = 5 & string str = "tempstring" at runtime.

It can be like

string[] st = freader.readline().split(' ');
if (st[0]=="int")
    {
      str[0] str[1] = str[4];
    }

I know that the above is the wrong syntax but I want to do something like this with some reference.

Can anybody help without using irony .net?

Marcelo Cantos
  • 181,030
  • 38
  • 327
  • 365
  • Have a look at http://stackoverflow.com/questions/508213/is-there-a-way-to-dynamically-execute-a-string-in-net-similar-to-eval-in-jav – John Mitchell Jul 15 '12 at 11:31
  • you can accomplish this sort of feature using Expression Trees – Glenn Ferrie Jul 15 '12 at 11:31
  • What about using dynamic? http://msdn.microsoft.com/en-us/library/dd264736.aspx – Dor Cohen Jul 15 '12 at 11:32
  • As others have said, what you're asking for is pretty advanced stuff. Perhaps explain why you're trying to do this - there may be a better approach. – Nik Jul 15 '12 at 11:48
  • I am developing prorgamme for a machine which will work with PLC. Now my application is interacting with PLC & should call around 130 text files as instructions into programme at runtime based upon decision made by PLC. writing 130-150 individual functions are difficult. – user1526791 Jul 15 '12 at 11:56

1 Answers1

0

This is relatively advanced material.
You can't really do as you said. C# is a strongly-typed language.
Although, you may seek to one of these solutions:

Mark Segal
  • 5,427
  • 4
  • 31
  • 69