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?

5
  • Have a look at stackoverflow.com/questions/508213/… Commented Jul 15, 2012 at 11:31
  • you can accomplish this sort of feature using Expression Trees Commented Jul 15, 2012 at 11:31
  • What about using dynamic? msdn.microsoft.com/en-us/library/dd264736.aspx Commented Jul 15, 2012 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. Commented Jul 15, 2012 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. Commented Jul 15, 2012 at 11:56

1 Answer 1

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:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.