Expression problem: Difference between revisions

Content deleted Content added
Citation bot (talk | contribs)
Alter: title, template type. Add: chapter-url, chapter. Removed or converted URL. | Use this bot. Report bugs. | Suggested by Headbomb | #UCB_toolbar
Arialdo (talk | contribs)
Problem description: Classes, interfaces and methods in C# sample needn't be all public
Tags: Mobile edit Mobile web edit
Line 126:
 
<syntaxhighlight lang="c#" line="1">
public interface IEvalExp
{
int Eval();
}
 
public class Lit : IEvalExp
{
publicinternal Lit(int n)
{
N = n;
}
 
publicinternal int N { get; }
 
public int Eval()
Line 146:
}
 
public class Add : IEvalExp
{
publicinternal Add(IEvalExp left, IEvalExp right)
{
Left = left;
Line 154:
}
 
publicinternal IEvalExp Left { get; }
 
publicinternal IEvalExp Right { get; }
 
public int Eval()
Line 164:
}
 
public static class ExampleOne
{
public static IEvalExp AddOneAndTwo() => new Add(new Lit(1), new Lit(2));
public static int EvaluateTheSumOfOneAndTwo() => AddOneAndTwo().Eval();
}
</syntaxhighlight>