Use a conditional attribute on the method, as shown below: class Debug{[conditional("TRACE")]public void Trace(string s){Console.WriteLine(s);}}class MyClass{public static void Main(){Debug.Trace("hello");}}In
Latest Answer : Well, you cant add the namespace System.Diagnostics.ConditionalAttribute. Actually you need to add the namespace System.Diagnostics and capitalise "Conditional" like so:using System;using System.Diagnostics;namespace Debug{ class ...
C# requires only a single parameter for delegates: the method address. Unlike other languages, where the programmer must specify an object reference and the method to invoke, C# can infer both pieces of
Latest Answer : This article is good.IntroductionIn this article I am going to share my knowledge on Delegates in C#.This would explain the Delegate using simple examples so that the beginner can understand the same.What is Delegate?Definition:Delegate is type which ...
Make sure that the target type set in the project properties setting is set to Windows Application, and not Console Application. If you're using the command line, compile with /target:winexe &
Latest Answer : Compile with following syntax at command line : csc /t:winexe ...
Yes. Set all references to null and then call System.GC.Collect().If you need to have some objects destructed, and System.GC.Collect() doesn't seem to be doing it for you, you can force finalizers
Latest Answer : GC.Collect();It is recomended that you should not forcefully call the GC. GC does it in the optimal way, since it knows the inner details like which object actually created inner objects.But some case you may need to force GC to free the scarce memory ...
No. C# does not have macros. Keep in mind that what some of the predefined C macros (for example, __LINE__ and __FILE__) give you can also be found in .NET classes like System.Diagnostics (for example,
Latest Answer : Ans:No ...
Here's a quick example of the DllImport attribute in action: using System.Runtime.InteropServices;class C{[DllImport("user32.dll")]public static extern int MessageBoxA(int h, string m, string
Latest Answer : ans:by using1st:using System.Runtime.InteropServicessecond step[DllImport("user32.dll")]use top of the class ...
Yes. Here's a simple example: using System;class Class1 {private string[] MyField;public string[] MyProperty {get { return MyField; }set { MyField = value; }}}class MainClass{public static int Main(string[]
Latest Answer : yes u can use indexer.its working is same as properties. ...
Unfortunately, this is currently not supported in the IDE. To do this from the command line, you must compile your projects into netmodules (/target:module on the C# compiler), and then use the command
Latest Answer : Ans:Unfortunately, this is currently not supported in the IDE. To do this from the command line, you must compile your projects into netmodules (/target:module on the C# compiler), and then use the command line tool al.exe (alink) to link these netmodules ...
You must use the Missing class and pass Missing.Value (in System.Reflection) for any values that have optional parameters.
Latest Answer : Ans:Yes,it is right.Answer: You must use the Missing class and pass Missing.Value (in System.Reflection) for any values that have optional parameters. ...
The easiest way is to use goto: using System;class BreakExample {public static void Main(String[] args) {for(int i=0; i
Latest Answer : Yes, there are ways to break out of nested loops. Although GOTO is allowed in C#, it is normally a bad idea, bad style, and indication of lack of good software development foundation of those who use it (no offense intended).Here are a couple of ...