.NET 101 Questions
Accessing System Variables
System.Windows.Forms.SystemInformation.ComputerName or Network, MousePresent, etc…
two or operators single | and double ||
The conditional-OR operator (||) performs a logical-OR of its bool operands, but only evaluates its second operand if necessary.
Binary | operators are predefined for the integral types and bool. For integral types, | computes the bitwise OR of its operands. For bool operands, | computes the logical OR of its operands; that is, the result is false if and only if both its operands are false.
There is also the ^ operator which checks if one and only one of the items is true.
I still prefer google “c# msdn PropertyName”
Wincv.exe is in c:\program files\Microsoft visual studio .NET\FrameworkSDK\Bin
Running EXE inside of EXE
Utilize System.Diagnostics.Process.Start( )
How to use existing Com Objects
register the dll the same way you normally would then
add through add reference in solution explorer
In static method of class, if
there is more than one instance of class which instance member values will be
accessed in static method?
1st - static members can only be accessed by a public static method or a public static property of a class. The method or property must be called with the class name not the name of an object.
2nd - Attempting to access an instance variable or an instance method from a static method is a compile error.
3rd - Using “this” in a static method is a compile error
public class classtest : System.Web.UI.Page
public static string getTest()
public static string getTest2()
//Error Herereturn strtest2;
public static string strtest = "blue";
public string strtest2 = "yellow";
private void Page_Load(object sender, System.EventArgs e)
// Put user code to initialize the page here
classtest cls1 = new classtest();
//Error HEREcls1.strtest = "red";
strTEST2 = classtest.getTest();
What are the conditions of using pointer in C# for safe code?
The portion of this lesson addresses this issue much better than I could.
A major problem with using pointers in C# is that C# operates a background garbage collection process. In freeing up memory, this garbage collection is liable to change the memory location of a current object without warning. So any pointer which previously pointed to that object will no longer do so. Such a scenario leads to two potential problems. Firstly, it could compromise the running of the C# program itself. Secondly, it could affect the integrity of other programs.
Because of these problems, the use of pointers is restricted to code which is explicitly marked by the programmer as 'unsafe'. Because of the potential for malicious use of unsafe code, programs which contain unsafe code will only run if they have been given full trust.
To address the problem of garbage collection, one can declare a pointer within a 'fixed' expression. This 'pins' the location of the type pointed to - the memory location of the type therefore remains static, safe from garbage collection. Note that the fixed statement can only be used within the context of unsafe code.
How do we use session variable in .net?
simply add variable name to session….
Session["DestPage"] = “red”
string strExample = Session[“DestPage”].ToString( );
Additionally there are Application and Page.User objects that can be instantiated and work like a session object.
What is the meaning of class modifiers
'internal', protected internal' and new?
This tutorial explains it much more clearly than I could. (listed in my favorite 3 overall c# tutorials)
also see - http://www.microsoft.com/mspress/books/sampchap/5798e.asp
Public The 'public' keyword identifies a type as fully accessible to all other types. This is the implicit accessibility of enumerator members (lesson 7) and interface members (lesson 11).
internal If a class is declared as 'internal', the type it defines is accessible only to types within the same assembly (a self-contained 'unit of packaging' containing code, metadata etc.). This is the default access level of non-nested classes.
protected If a class is declared as 'protected', its type is accessible by a containing type and any type that inherits from this containing type. This modifier should only be used for internal classes (ie. classes declared within other classes).
protected internal The permissions allowed by this access level are those allowed by the 'protected' level plus those allowed by the 'internal' level. The access level is thus more liberal than its parts taken individually. This modifier should only be used for internal classes (ie. classes declared within other classes).
private Where a class is declared as 'private', access to the type it defines is limited to a containing type only. This modifier should only be used for internal classes (ie. classes declared within other classes).
We now turn to the final three class modifiers:
new The 'new' keyword can be used for 'nested' classes. A
nested class is one that is defined in the body of another class; it is in most
ways identical to a class defined in the normal way, but its access level
cannot be more liberal than that of the class in which it is defined. A nested
class should be declared using the 'new' keyword just in case it has the same
name as (and thus overrides) an inherited type.
abstract A class declared as 'abstract' cannot itself be instanced - it is designed only to be a base class for inheritance.
sealed A class declared as 'sealed' cannot be inherited from.
Or from another source – (C# Professor)
Ø A derived class cannot be more accessible that its base class. (can’t derive public class from a private class)
Ø A class can be more accessible that its base interfaces.
Ø An interface cannot be more accessible than any of its base interfaces
Ø An interface method is implicitly public so the implementing method must be explicitly declared public, else it defaults to being private.
Ø When defining an explicit interface method implementation, you cannot specify an access specifier.
Ø There is no private inheritance in C# - only public inheritance.
Ø Remember that constructors are not inherited and that C# does not support multiple inheritance (each class can have only one parent)
Ø Nested classes can be declared with any of the five types of accessibility.
Ø Accessibility modifiers cannot be used with destructors
The following terms mean basically the same thing whether they are applied to a variable, an inner class, or an interface.
Public to any code that has an object of the class
Accessible from anywhere
Only visible to code within the class
Not even derived classes have direct access.
Private is default but it is considered bad style not to write it anyway
Accessible from within any part of the .NET assembly. (sort of like friendship in C++ and VB)
Public within assembly/private outside of assembly
Accessible from within class and from all derived classes
Members of a derived class can access all of the protected members of their base class. (protected members are public to children*)
Protected members of a class are private to any class that is not a child.
Accessible from within assembly or from children even though they are outside of assembly
Allows the child class to override a method in the parent class even though the parent method has not be declared as overridable by using the virtual keyword.
Using new hides the parent’s version of the method
Declaring a child method new allows it to be overriden by any children it has
Use new when the child’s method with the same name as the parents will have different parameters and thus cause a warning message.
New will stop warning messages when a name clash is not accidental – it tells the program that “I’m the programmer and I’ll do what I want.”
The class cannot be instantiated (no objects of the class can be created)
An abstract class cannot be sealed( no way to use it!)
Abstract method must be overridden in children
A sealed class cannot have children. Sometimes helps optimizing operations at runtime
*also to children’s children, etc.
Books I’ve been using most since I started using .NET
Programming Data Driven Web Applications with ASP.NET – Mack, Seven
Programming ASP.NET, by Jesse Liberty & Dan Hurwitz
Transact- SQL Programming, Gould, Zanevesky, Kline.
Links / Tutorials
***** Exellent - Comprehensive Data Grid Tutorial
**** Very Good Chapter of a book available online.
Beginning C# Using Windows Form Controls
*** Three good overall C# Tutorials - Both have about over 15 lessons (very printable)
**** Very Good Xpath Reference/Turorial
Top 10 Tips for ASP.NET
Getting Started with C#
C# Regular Expressions
You can use .NET without buying VS.NET (VB)
ADO.NET parts 1 – 5
Java vs. C#
GotDotNet Tutorials - Good work through (not
really printable) but thorough
MSDN Users Group
MSDN C# Users Group
C# Web Scraping
VB to C# converter
C#, VB, JScript Quick Reference (not comprehensive, but good starting point for comparisons)
Big HTTP Request sample
Splitting and Joining Strings
http://www.devguru.com/ (best scripting site by far)
Example Code List
More Sample Chapters
.NET Framework User Controls and Custom Server Controls
Programming ASP.NET 2nd Ed- Programming Web Forms
Microsoft.NET for programmers – Case Study –
Video Poker Machine.
Inside C# - Strings/Regex
ASP.NET Kick Start – Creating Basic Web Form Pages
Professional C# 2nd Ed. – Data Access with .NET
C# & OOP
Sample Chapter on CLR
SMTP Mail without CDO