.NET
101 Questions
Accessing System Variables
System Information
http://www.codeproject.com/csharp/sysinfo.asp?target=operating%7Csystem
System.Windows.Forms.SystemInformation.ComputerName
or Network, MousePresent,
etc…
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformssysteminformationclasscomputernametopic.asp
OR operator
two or operators single | and double ||
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfCSharpOperators.asp
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.
Class Viewer
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( )
http://www.csharpfriends.com/Forums/ShowPost.aspx?PostID=13014
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()
{
return
strtest;
}
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";
string
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.
http://www.softsteel.co.uk/tutorials/cSharp/lesson5.html
portion below
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.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUIPageClassUserTopic.asp
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)
http://www.softsteel.co.uk/tutorials/cSharp/lesson12.html
also see - http://www.microsoft.com/mspress/books/sampchap/5798e.asp
portion below
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.
|
ACCESSIBILITY MODIFIERS |
|
|
public |
Public to any code that has an object of the class Accessible from anywhere |
|
private |
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 |
|
internal |
Accessible from within any part of the .NET assembly. (sort of like friendship in C++ and VB) Public within assembly/private outside of assembly |
|
protected |
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. |
|
protected internal |
Accessible from within assembly or from children even though they are outside of assembly |
|
OTHER SPECIFIERS |
|
|
new |
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.” |
|
abstract |
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 |
|
sealed |
A sealed class cannot have children. Sometimes helps optimizing operations at runtime |
*also to children’s children, etc.
3
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
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx
**** Very Good Chapter of a book available online.
Beginning C# Using Windows Form Controls
http://www.codeproject.com/books/1861004982.asp
*** Three good overall C# Tutorials - Both have about over 15 lessons (very
printable)
http://www.softsteel.co.uk/tutorials/cSharp/cIndex.html
http://www.csharp-station.com/
http://www.programmersheaven.com/2/Les_CSharp_0
**** Very Good Xpath Reference/Turorial
http://www.w3schools.com/xml/default.asp
C# Tutorials
http://www.c-sharpcorner.com/language.asp
Top 10 Tips for ASP.NET
http://www.ondotnet.com/pub/a/dotnet/2002/04/22/asptips.html
File IO
http://www.ondotnet.com/pub/a/dotnet/2002/08/05/io.html
Getting Started with C#
http://www.ondotnet.com/pub/a/dotnet/excerpt/learningcsharp_2/index1.html
http://www.ondotnet.com/pub/a/dotnet/excerpt/learningcsharp_2/index2.html
C# Regular Expressions
http://www.ondotnet.com/pub/a/dotnet/2002/03/11/regex2.html
You can use .NET without buying VS.NET (VB)
http://www.ondotnet.com/pub/a/dotnet/2002/02/11/hackdotnet.html
ADO.NET parts 1 – 5
http://www.ondotnet.com/pub/a/dotnet/2001/06/07/csharp_java.html
Java vs. C#
http://www.javacamp.org/javavscsharp/
GotDotNet Tutorials - Good work through (not
really printable) but thorough
http://samples.gotdotnet.com/quickstart/aspplus/
C# Keywords Reference
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vaidxarrays.asp
MSDN Users Group
MSDN
C# Users Group
C# Web Scraping
http://www.activedataonline.com.au/articles/PaypalIPN.aspx
VB to C# converter
http://authors.aspalliance.com/aldotnet/examples/translate.aspx
http://www.ellkay.com/ConvertVB2CSharp.htm
C#, VB, JScript Quick Reference (not comprehensive,
but good starting point for comparisons)
http://www.werelight.com/docs/dotnet_lang_quickref.htm
DotNet
http://www.denvervisualstudio.net/
Viewstate Optimization
http://www.webreference.com/programming/asp/viewstate/
Microsoft Newsgroup
http://msdn.microsoft.com/newsgroups/default.asp?url=/newsgroups/loadframes.asp?icp=msdn&slcid=us&newsgroup=microsoft.public.dotnet.languages.vb
Big HTTP Request sample
http://www.aspemporium.com/aspEmporium/cshrp/howtos/howto.asp?hid=13
Splitting and Joining Strings
http://www.csharp-station.com/HowTo/StringJoinSplit.aspx
Good
Reference Sites
http://4guysfromrolla.com/
http://www.asp.net/Default.aspx?tabindex=0&tabid=1
http://www.devguru.com/ (best scripting site by far)
Lists
of tutorials/ Articles
http://www.411asp.net/home/tutorial/specific
http://www.codeproject.com/aspnet/
http://www.codeproject.com/dotnet/
http://www.codeproject.com/csharp/
http://www.codeproject.com/cs/database/
http://authors.aspalliance.com/das/
http://www.aspalliance.com/ArticleListing.aspx
http://www.developersdex.com/asp/default.asp?p=915
http://www.15seconds.com
http://www.gotdotnet.com/community/resources/Default.aspx?ResourceTypeDropDownList=Articles&SortDirection=Desc&SortColumnName=CreationDate
Example Code List
http://www.asp101.com/samples/index.asp
More
Sample Chapters
.NET Framework User Controls and Custom Server Controls
http://www.oreilly.com/catalog/dotnetfrmess3/chapter/ch02.pdf
http://www.oreilly.com/catalog/dotnetfrmess3/chapter/ch02.pdf
Programming ASP.NET 2nd Ed- Programming Web Forms
http://www.oreilly.com/catalog/progaspdotnet2/chapter/ch06.pdf
Programming in the .NET Environment – Type System
http://www.codeproject.com/books/WatkinsChap2.asp
Learn XML in a weekend – Programming with XML
http://www.codeproject.com/books/lxiaw.asp
Microsoft.NET for programmers – Case Study –
Video Poker Machine.
http://www.codeproject.com/books/lxiaw.asp
Inside C# - Strings/Regex
http://www.codeproject.com/books/0735616485.asp
ASP.NET Kick Start – Creating Basic Web Form Pages
http://www.codeproject.com/books/0735616485.asp
Professional C# 2nd Ed. – Data Access with .NET
http://www.sitepoint.com/article/853
C# & OOP
http://www.sitepoint.com/article/853
http://www.developer.com/net/net/article.php/11087_1435351_2
http://www.4GuysFromRolla.com/webtech/091800-1.shtml
Framework
stuff
Installing ASP.NET
http://www.asp101.com/lessons/install.asp
Sample Chapter on CLR
http://www.oreilly.com/catalog/dotnetfrmess3/chapter/ch02.pdf
SMTP Mail without CDO
http://www.eggheadcafe.com/articles/20030316.asp