|
Judah H. wrote:
we won't do your homework for you
It doens't look like homework to me. It was clear to me that the test in question has happened and is in the past therefor any answers gained here are irrelevant to the result of the test.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
|
|
|
|
|
4. Which of the following statements is FALSE:
A. Reflection can be used to examine the contents of an assembly.
B. Reflection can be used to find the types associated with a module.
C. Reflection can be used to find the events associated with a type.
D. Reflection can be used to find the types base class.
E. Reflection can be used to find the types associated with a namespace.
A. this answer is not really descriptive enough. What do they mean by content of assembly?
If it's type information, then True.
B. TRUE. Module.GetTypes()
C. TRUE. Type.GetEvents()
D. TRUE. Type.BaseType
E. Can't be derived easily, but you can go thru all loaded assemblies, and thru all types and get the namespaces. But you won't get all, as you can define types to belong in a namespace in a different module that's not event loaded.
|
|
|
|
|
Alvaro Mendez wrote:
1. What is the purpose of the definite assignment in C#:
D. You must assign a value to a variable before you use it
You'll get warnings that say this from the compiler itself, if you try to use a variable before it has been assigned.
Alvaro Mendez wrote:
2. Which of the following statements is FALSE:
I know that A is true. If D was true, then B and C would both technically be false, so I would say that D is false. (Another helpful bit of info is that the JIT doesn't generally compile code until it needs to run it. So, until code that would need to reference an not-yet-loaded dll is called, that dll shouldn't be loaded.) (Also! There are way too many ways to load an assembly dynamically whenever you feel like it for B and C to really apply at all unless they are talking about default behavior of the CLR.)
Alvaro Mendez wrote:
3. There are two kinds of attributes in C#:
Assuming that "attributes" means the classes derived from System.Attribute, then A would be the only applicable answer, I think. B is possible, but would apply to basically everything in the .NET Framework if that was the correct answer. C is totally irrelevant, since that would be about Properties. D is obviously related more to a stack than to the C# language.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
John Fisher wrote:
You'll get warnings
Errors! Not warnings A pain in the ASS.
top secret
|
|
|
|
|
1. D //you dont even wanna see my bitching in my code about this!
Short explaination (csc complains):
int l;
if (somebool)
{
l = 0;
}
if (somebool)
{
COnsole.WriteLine(l);
}
2.A (they are an extention to PE files),D (see B & C)
3.I would say A, as the rest is even more absurd!
4. None (maybe A, they dont define contents)
top secret
|
|
|
|
|
I agree with most of what you said, and for an explanation of (3), go here: http://www.ondotnet.com/pub/a/dotnet/excerpt/prog_csharp_ch18/index.html?page=2#attributes
But for number 4, I believe E is the one that's false. How could you use reflection to find the types associated with a namespace? I'm not terribly familiar with C# reflection, since I've only done a small amount work with it, but I couldn't find any methods or classes in the reflection namespace which would allow for investigating namespaces specifically. Since assemblies are loaded only when needed (or explicitly loaded), most types in any given namespace wouldn't be available to reflection anyway.
Reflection can be used to identify the types associated with a namespace in one specific assembly, but without already knowing exactly which assemblies contain types within a specific namespace, how would one really list all the types associated with a namespace?
|
|
|
|
|
Curi0us_George wrote:
But for number 4, I believe E is the one that's false. How could you use reflection to find the types associated with a namespace?
You can enumerate all types in all assemblies and compare namespaces with the type you're searching for. The reflection classes don't have any methods that will get you types for a namespace, but it is possible.
And just because types aren't JIT'd until they're used doesn't mean reflection can't see them. It can get all the type information without actually loading and JIT'ing the type because it uses the metadata in the assembly.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How would you go about enumerating all assemblies? And if you're going to say that you can manually walk the path, I'd say you're no longer just doing reflection. At some point, you're tacking on too much functionality to legitimately call it a part of the feature set.
|
|
|
|
|
Enumerating assemblies would be application-specific. You could enumerate all loaded assemblies (AppDomain.GetAssemblies ), load and enumerate all assemblies in a directory, etc.
To what degree you can call this reflection is a matter of opinion, though. You're still using reflection to gather this information and only simple collection storage and enumeration plus string comparisons to compare, but you wouldn't be there without reflection. More than any answer, I agree this is the wrong answer for that question but in my opinion they're all right. Too many times I've seen tests made up by people that really don't know the technology as well as they should before considering themselves an authority.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I can see how you might call this reflection, but I wouldn't. It's like loading all the classes in the java path and then using reflection to find out which classes belong to a specific package. It works, but it's not a built in capability, per se.
>> Too many times I've seen tests made up by people that really don't know the technology as well as they should before considering themselves an authority.
Definitely true.
|
|
|
|
|
i've got a ijl15.dll so how can i import it into my c# project.
how to know which functions are there in ijl15.dll ? and how to use it ?
thanks...
|
|
|
|
|
You can use the Dependency Walker (depends.exe, comes with the Platform SDK which is installed by default with Visual Studio) to see the functions exported from the native library.
Read Interoperating with Unmanaged Code[^] in the .NET Framework SDK.
If your library contains exported functions, you use the DllImportAttribute to declare them as externed methods for use in your classes. If it is a COM server, you import the typelib using tlbimp.exe (or VS.NET can do it if you add a reference to a COM library) and, optionally, ActiveX controls using aximp.exe (which VS.NET can also do if you add an ActiveX reference to your toolbar and drag it on your form).
Everything you need to know is in the first link above.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is it possible to Dock your application to the System (Desktop). An very good example of such an application is "Magnifier" which comes bundled with Windows. Your application should behave like a Toolbar.
It should so happen that the application should always be active and all the other application open should not overlap your application.
Is it possible to do this ?
CHEERS
- NAGU
|
|
|
|
|
|
I am developing a software where in I require to block the usage of Keyboard and Mouse and hence forth deny the usage of the system to the user.
With KeyEventArgs I can block the usage of certain individual characters. But since i want to deny access of the whole system to the user, I need to mask even the Keyboard events such as "Alt+Tab" or "Ctrl+Alt+Del" etc...
Any kind of help is appreciated.
CHEERS
- NAGU
|
|
|
|
|
You can do this, or at least partially do this, utilizing Win32 keyboard and mouse hooks. Search the articles of this site, there's a few good ones covering Win32 hooks in .NET.
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|
If you want to disable everything except a key combination you want to unlock the keyboard and mouse, you'll have to write a low-level keyboard hook into your app. This will let you get keyboard messages system wide.
You might want to read this article on CP[^] for a little hooking in C# and follow the links in that article to some work by Dino Esposito on the subjet.
Also, search through the posts here in C# and VB.NET for some discussions on hooking the keyboard.
RageInTheMachine9532
|
|
|
|
|
A simpler way is to add an IMessageFilter using Application.AddMessageFilter and doesn't require P/Invoking anything or using low-level hooks. It simply gives your implementation a chance to filter messages before they're dispatched to their target windows (controls).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hmmm... Didn't know that. I'll look into that for future reference. Thanks Heath!
RageInTheMachine9532
|
|
|
|
|
A much easier way and more efficient way (without having to P/Invoke native APIs) is to simply add a IMessageFilter to pre-filter any messages sent to ONLY your application (as opposed to using a system-wide, low-level keyboard hook).
using System;
using System.Drawing;
using System.Windows.Forms;
public class Test : Form, IMessageFilter
{
static void Main(string[] args)
{
Test t = new Test();
Application.AddMessageFilter(t);
Application.Run(t);
Application.RemoveMessageFilter(t);
}
public Test()
{
TextBox tb = new TextBox();
tb.Location = new Point(8, 8);
this.Controls.Add(tb);
tb = new TextBox();
tb.Location = new Point(8, 30);
this.Controls.Add(tb);
}
private const int WM_KEYDOWN = 0x0100;
private const int WM_LBUTTONDOWN = 0x0201;
private const int WM_RBUTTONDOWN = 0x0204;
private const int WM_XBUTTONDOWN = 0x020b;
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == WM_KEYDOWN ||
m.Msg == WM_LBUTTONDOWN ||
m.Msg == WM_RBUTTONDOWN ||
m.Msg == WM_XBUTTONDOWN)
return true;
return false;
}
} Pay attention to the PreFilterMessage method, which is the implementation for IMessageFilter.PreFilterMessage . You could filter other application messages this way as well. Anything that goes through the application message pump can be filtered.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I really was informed by these information, Thank you Heath.
But how can one get the constant values for messages like WM_KEYDOWN...etc.
Medhat Ramses
|
|
|
|
|
They are defined in the header files, take a look at windows.h for example.
- Nick Parker My Blog
|
|
|
|
|
how do i put a scroll on a picture box or just how do i create a image where i can scroll
can somebody give me code examples
chad
|
|
|
|
|
Place your PictureBox control onto another panel. Whenever you set the bitmap of the PictureBox control, set the size of the PictureBox control to be the size of the bitmap. A Windows scrollbar will appear allowing you to scroll.
Additionally, you can write your own control to do this, but that's probably a little more work.
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|