Click here to Skip to main content
15,907,329 members
Home / Discussions / C#
   

C#

 
GeneralRe: My thoughts on C# Pin
#realJSOP2-Jun-19 4:19
professional#realJSOP2-Jun-19 4:19 
GeneralRe: My thoughts on C# Pin
jschell2-Jun-19 8:49
jschell2-Jun-19 8:49 
GeneralRe: My thoughts on C# Pin
Brian_TheLion2-Jun-19 19:46
Brian_TheLion2-Jun-19 19:46 
GeneralRe: My thoughts on C# Pin
F-ES Sitecore2-Jun-19 23:19
professionalF-ES Sitecore2-Jun-19 23:19 
GeneralRe: My thoughts on C# Pin
Brian_TheLion3-Jun-19 12:26
Brian_TheLion3-Jun-19 12:26 
GeneralRe: My thoughts on C# Pin
Nathan Minier4-Jun-19 1:31
professionalNathan Minier4-Jun-19 1:31 
GeneralRe: My thoughts on C# Pin
Brian_TheLion4-Jun-19 14:16
Brian_TheLion4-Jun-19 14:16 
GeneralRe: My thoughts on C# Pin
Nathan Minier4-Jun-19 14:26
professionalNathan Minier4-Jun-19 14:26 
GeneralRe: My thoughts on C# Pin
Brian_TheLion4-Jun-19 14:30
Brian_TheLion4-Jun-19 14:30 
GeneralRe: My thoughts on C# Pin
Nathan Minier4-Jun-19 14:40
professionalNathan Minier4-Jun-19 14:40 
GeneralRe: My thoughts on C# Pin
Brian_TheLion4-Jun-19 14:53
Brian_TheLion4-Jun-19 14:53 
GeneralRe: My thoughts on C# Pin
Nathan Minier4-Jun-19 14:47
professionalNathan Minier4-Jun-19 14:47 
GeneralRe: My thoughts on C# Pin
Brian_TheLion4-Jun-19 15:12
Brian_TheLion4-Jun-19 15:12 
GeneralRe: My thoughts on C# Pin
Nathan Minier4-Jun-19 15:29
professionalNathan Minier4-Jun-19 15:29 
GeneralRe: My thoughts on C# Pin
Brian_TheLion4-Jun-19 16:37
Brian_TheLion4-Jun-19 16:37 
GeneralRe: My thoughts on C# Pin
Brian_TheLion4-Jun-19 15:28
Brian_TheLion4-Jun-19 15:28 
GeneralRe: My thoughts on C# Pin
Brian_TheLion4-Jun-19 15:38
Brian_TheLion4-Jun-19 15:38 
GeneralRe: My thoughts on C# Pin
Nathan Minier4-Jun-19 15:41
professionalNathan Minier4-Jun-19 15:41 
GeneralRe: My thoughts on C# Pin
Gerry Schmitz4-Jun-19 6:53
mveGerry Schmitz4-Jun-19 6:53 
GeneralRe: My thoughts on C# Pin
Brian_TheLion4-Jun-19 18:44
Brian_TheLion4-Jun-19 18:44 
QuestionHow to perform the content of a variable as a C# instruction Pin
Member 133074841-Jun-19 10:02
Member 133074841-Jun-19 10:02 
AnswerRe: How to perform the content of a variable as a C# instruction Pin
BillWoodruff1-Jun-19 15:33
professionalBillWoodruff1-Jun-19 15:33 
First: understand that C# is a strongly typed (early binding) language where all references must be resolved by the compiler before program execution. That fundamental reality means you cannot have a REPL (read-evaluate-do-stuff-and-return-results-loop) that defers execution of arbitrary code until run-time (late-binding) [^].

However, you can kind-of implement REPL in C# by using 3rd. party libraries like CShell [^], the one built into Mono, the one available in the Roslyn compiler, and by exotic code in your own DSL.

All of these methods of achieving late-binding are expensive computationally !

What you can do is create a Dictionary with Keys of whatever, and Values of executable code; I wrote about this 13 years ago: [^]; today's C# makes the syntax a bit easier:
public Dictionary<int, Action> Instructions = new Dictionary<int, Action>
{
    {1, () => s = i * 2 },
    {2, () => lbl.Text = $"Hi dash: {string.Concat(Enumerable.Repeat('-', i * 3))}{'\\'}"},
    {3, () => timer.Dispose()},
    {4, () => MessageBox.Show("Wrong Number") }
};
If you then call Instructions [4](); in a method ... voila a modal dialog.

But, note carefully: for this code to compile the variables 'i, 's, and the Label 'lbl, and the Timer 'timer must all be defined, and any variable that is not auto-initialized ('int and 'string are auto-initialized) must have an initial value set !
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot


modified 2-Jun-19 0:27am.

GeneralRe: How to perform the content of a variable as a C# instruction Pin
Member 133074841-Jun-19 18:22
Member 133074841-Jun-19 18:22 
AnswerRe: How to perform the content of a variable as a C# instruction Pin
jschell2-Jun-19 8:53
jschell2-Jun-19 8:53 
QuestionHow To Make This Generic Pin
Kevin Marois31-May-19 11:55
professionalKevin Marois31-May-19 11:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.