Difference between ref and out in .net

July 28th, 2009 admin

There are a couple of ways getting output parameters from .net procedures: you can use the keyword out or the keyword ref. Like so:

public void DoSmth(ref int nRefVar){}

or

public void DoSmth(out int nOutVar){}

What's the difference? Well, that's pretty easy. To pass a variable by reference, first you have create that reference by initializing the variable. Usually you want to use this way when you're gonna use the value of the variable inside the function.

public void DoSmth(ref int nRefVar)
{
if (nRef > 10)
nRef = 5;
else
nRef = 25;
}
int nRefVar = 10;
DoSmth(ref nRefVar);

To pass a variable as an out parameter you have only to declare it first. This way is just for getting the value. Usually you will need it when you have to get more than one return value from a procedure.

public void DoSmth(out int nOutVar1, out int nOutVar2)
{
nOutVar1 = 1;
nOutVar2 = 2;
}
int nOutVar1, nOutVar2;
DoSmth(out nOutVar1, out nOutVar2);

Good Luck

Posted in asp.net, c#, development | No Comments »

asp.net interview question

July 24th, 2009 admin

Here is a list of some basic ASP.Net interview question. I've come across them here: http://weblogs.asp.net/anasghanem/archive/2008/02/22/common-net-technical-questions-that-you-will-be-asked-about-in-the-interviews.aspx

For those who looks for a new job :)

1. Explain the life cycle of an ASP .NET page.
2. Explain the .NET architecture.
3. What are object-oriented concepts?
4. How do you create multiple inheritance in c# and .NET?
5. When is web.config called?
6. Differences between DLL and EXE?
7. Can an assembly have EXE?
8. Can a DLL be changed to an EXE?
9. Compare & contrast rich client (smart clients or Windows-based) & browser-based Web application
10. Compare Client server application with n-Tier application
11. Can a try block have more than one catch block?
12. Can a try block have nested try blocks?
13. How do you load an assembly at runtime?
14. If I am writing in a language like VB or C++, what are the procedures to be followed to support .NET?
15. How do you view the methods and members of a DLL?
16. What is shadowing?
17. What are the collections you’ve used?
18. What is a static class?
19. What is static member?
20. What is static function?
21. What is static constructor?
22. How can we inherit a static variable?
23. How can we inherit a static member?
24. Can we use a static function with a non-static variable?
25. How can we access static variable?
26. Why main function is static?
27. What is garbage collection?
28. Can we force garbage collector to run?
29. What is reflection?
30. What are different type of JIT?
31. What are Value types and Reference types?
32. What is concept of Boxing and Unboxing?
33. What’s difference between VB.NET and C#?
34. What’s difference between System exceptions and Application exceptions?
35. What is CODE Access security?
36. What is a satellite assembly?
37. How to prevent my .NET DLL to be decompiled?
38. What’s the difference between Convert.toString and .toString() method ?
39. What is Native Image Generator (Ngen.exe)?
We have two version of the same assembly in GAC? I want my client to make choice which assembly to choose?
40. What is CodeDom?

Posted in asp.net, c# | No Comments »