Sunday, March 29, 2015

How do I do implement a trace and assert?

Question:How do I do implement a trace and assert??

Answer: </P><P align=justify>Use a conditional attribute on the method, as shown below: </P><P align=justify>class Debug</P><P align=justify>{</P><P align=justify>[conditional("TRACE")]</P><P align=justify>public void Trace(string s)</P><P align=justify>{</P><P align=justify>Console.WriteLine(s);</P><P align=justify>}</P><P align=justify>}</P><P align=justify></P><P align=justify>class MyClass</P><P align=justify>{</P><P align=justify>public static void Main()</P><P align=justify>{</P><P align=justify>Debug.Trace("hello");</P><P align=justify>}</P><P align=justify>}</P><P align=justify></P><P align=justify>In this example, the call to Debug.Trace() is made only if the preprocessor symbol TRACE is defined at the call site. You can define preprocessor symbols on the command line by using the /D switch. The restriction on conditional methods is that they must have void return type.

Tags:Interview Questions, Microsoft, C#,

Please submit your Interview Answer for the above Question via replying to this post. Thank you for visiting to our blog, Have a Good Day!.



Sponsor Advertisement



School Administration Software

School Management System Software

This is One of the best School management system software in the world. School Software offers complete professional institute management system administration, library, accounting, inventory, etc for all the school activities management...

No comments:

Post a Comment