I.T. Discussion Community!
-Collapse +Expand
C#
Search C# Group:

Advanced
-Collapse +Expand C# To/From
To/FromCODEGuides
-Collapse +Expand C# Study Test
PRESTWOODCERTIFIED
-Collapse +Expand C# Store
PRESTWOODSTORE
   ► KBProgrammingC#   Print This     

C# KB: C# Topic

The primary version of the CSharp language targeted in this topic is Microsoft Visual C#. Whenever possible, we will also test code, document, and promote CodeGear's C#Builder and generic C#.

Topics

82 Articles Found in the C# Topic  (or one of the sub-topics in bold above)

  KB Article    

Wes Peterson
1. [DllImport] attribute

This code allows you to use Win32 DLLs in your .NET applications.

Posted to KB Topic: WinForms
11 years ago

Code
Nothing New Since Your Last Visit
10685
Hits

C# (Visual C# & VS.Net)

Bryan Valencia
2. A 10 Minute C# Console Application Quick Start

This will show how to make a "hello world" console application in Visual Studio 2008 with C#. Let VS.Net do the work and create a new console application using the menu. Use Console.WriteLine and Console.ReadLine for simple input and output.

10 years ago, and updated 10 years ago

Article
Nothing New Since Your Last Visit
13567
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
3. A 10 Minute C# Winforms Quick Start

The ButtonsCS project. Create a classic "Hello, World" application using Visual Studio .Net with C# syntax. Requires either the full version or Visual C# Express Edition.

Posted to KB Topic: WinForms
10 years ago

Article
Nothing New Since Your Last Visit
16876
Hits

C# (Visual C# & VS.Net)

Stephen Berry
4. Applying the Built-in ASP.NET User-Login Functionality to Your Database Using aspnet_regsql.exe to set up a database to support the functionality of ASP.NET 2.0's built-in membership.
10 years ago, and updated 10 years ago
(1 Comments , last by chris.l4 )

KB Post
Nothing New Since Your Last Visit
5557
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
5. ASP.NET Extension Information This article describes the ASPX file extensions.
Posted to KB Topic: WebForms Coding Tasks
16 years ago, and updated 10 years ago

KB Post
Nothing New Since Your Last Visit
7946
Hits

C# (Visual C# & VS.Net)

Stephen Berry
6. Associative Arrays in C# (a Dictionary)

A Dictionary is a data type which maps a key to a value. The key and the value can be any type, the Dictionary shows the link between the two.

This example shows the relationship between the 3-letter airport code and their location. The code will produce a message box which says "Los Angeles."

Posted to KB Topic: Language Basics
10 years ago
(2 Comments , last by funny.j )

Code
Nothing New Since Your Last Visit
13228
Hits

C# (Visual C# & VS.Net)

Wes Peterson
7. Attribute An attribute is a "shorthand" mechansim for having additional metadata included in your assembly.
Posted to KB Topic: Language Basics
11 years ago, and updated 10 years ago

Definition
Nothing New Since Your Last Visit
9310
Hits

C# (Visual C# & VS.Net)

Stephen Berry
8. Boxing and Unboxing

Boxing is the conversion of a value type to the object type (or to any interface type that is implemented by the value type). Unboxing is the conversion from an object type to a value type (or from an interface type to any value type that is implemented by the value type).

Posted to KB Topic: Language Basics
10 years ago, and updated 9 years ago

KB Post
Nothing New Since Your Last Visit
7462
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
9. C# Abstraction (abstract, override)

C# supports abstract class members and abstract classes using the abstract modifier. An abstract class is a class with one or more abstract members and you cannot instantiate an abstract class. However, you can have additional implemented methods and properties. An abstract member is either a method (implicitly virtual), property, indexer, or event in an abstract class. You can add abstract members ONLY to abstract classes using the abstract keyword.

Posted to KB Topic: OOP
10 years ago, and updated 9 years ago

Code

Article
Nothing New Since Your Last Visit  
31637
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
10. C# Access Modifiers

In C#, you specify each class and each class member's visibility with an access modifier. The C# access modifiers are the traditional public, protected, and private plus the two additional .Net modifiers internal and protected internal.

Internal indicates members are accessible from types in the same assembly. Protected internal indicates members are accessible from types in the same assembly as well as descendant classes. OO purist might object to internal and protected internal and I suggest you choose private, protected, or public over them until you both fully understand them and have a need that is best suited by them.

The default for class and class members is Internal (members are accessible from types in the same assembly). This is different than with interfaces where the default for an interface is Internal but an interface's members are always public -- which makes sense but is noteworthy.

With both classes and interfaces, if you make a class public, the members are public. This applies to the other access modifiers too. For example, if you make a class protected, the members default access modifiers are protected.

Posted to KB Topic: OOP
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit  
8754
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
11. C# Assignment (=)

Languages Focus: Assignment

Common assignment operators for languages include =, ==, and :=. An assignment operator allows you to assign a value to a variable. The value can be a literal value like "Mike" or 42 or the value stored in another variable or returned by a function.

C# Assignment

C# uses = for it's assignment operator.

Posted to KB Topic: Tool Basics
10 years ago, and updated 10 years ago
(1 Comments , last by quick.e )

Code
Nothing New Since Your Last Visit
5636
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
12. C# Associative Array (Dictionary)

General Info: Associative Array

A set of unique keys linked to a set of values. Each unique key is associated with a value. Think of it as a two column table. MyArray['CA'] = 'California' MyArray['AR'] = 'Arizona'

Languages Focus: Associative Array

Associative arrays are also known as a dictionary or a hash table in other languages.

C# Associative Array

Posted to KB Topic: Language Details
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
20623
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
13. C# Base Class (System.Object)

In C#, the Object keyword is an alias for the base System.Object class and is the single base class all classes ultimately inherit from.

Posted to KB Topic: OOP
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit  
7178
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
14. C# Case Sensitivity (Yes)

C# is case sensitive. The following does NOT:

messagebox.Show("hello"); //Does not work!

The first time you type any other case for commands or variables, VS.Net will change it to the accepted or defined case. For example, if you type messagebox.show it is converted to MessageBox.Show. Once corrected, you can break it again by editing MessageBox to messagebox and the compiler will give you an error.

Posted to KB Topic: Tool Basics
10 years ago, and updated 9 years ago

Code

KB Post
Nothing New Since Your Last Visit  
8979
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
15. C# Class..Object (class...new)

In C#, you use the class keyword to specify a class and you signify its parent with a colon and the name of the parent class. When you instantiate an object from a class, you use the new keyword.

Posted to KB Topic: OOP
10 years ago, and updated 9 years ago

Code

KB Post
Nothing New Since Your Last Visit  
10766
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
16. C# Code Blocks ({ })

For C#, I prefer to put the opening { and the closing } on their own line (as opposed to C++, Java, and JavaScript where I put the opening bracket at the end of the first line.

Posted to KB Topic: Language Basics
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
6399
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
17. C# Comparison Operators (==, !=)

General Info: Round Floating Point Numbers

When comparing floating point numbers, make sure you round to an acceptable level of rounding for the type of application you are using.

Languages Focus: Comparison Operators

A comparison operator compares two values either literals as in "Hello" and 3 or variables as in X and Counter. Most languages use the same operators for comparing both numbers and strings. Perl, for example, uses separate sets of comparison operators for numbers and strings.

C# Comparison Operators

Common comparison operators:

== equal
!= not equal
< less than
> greater than
<= less than or equal
>= greater than or equal

Posted to KB Topic: Tool Basics
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
8711
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
18. C# Constants (const)

In C#, you define constants with the const keyword.

All constants are part of a class (no global constants) but you can make a constant public and have access to it so long as you have added the class to the project (even without creating the class as if they were static, but you cannot use the static keyword).

Constants must be of an integral type (sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, bool, or string), an enumeration, or a reference to null.

Posted to KB Topic: Tool Basics
9 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit  
9539
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
19. C# Constructors (Use class name)

In C#, a constructor is called whenever a class or struct is created. A constructor is a method with the same name as the class with no return value and you can overload the constructor. If you do not create a constructor, C# will create an implicit constructor that initializes all member fields to their default values.

Constructors can execute at two different times. Static constructors are executed by the CLR before any objects are instantiated. Regular constructors are executed when you create an object.

Posted to KB Topic: OOP
9 years ago, and updated 9 years ago

Code

Article
Nothing New Since Your Last Visit  
14518
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
20. C# Custom Routines
ReturnType RoutineName()

 

Note: C# requires () in both the function declaration, and when it's invoked.

Posted to KB Topic: Language Basics
10 years ago, and updated 10 years ago

Code
Nothing New Since Your Last Visit
7127
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
21. C# Deployment Overview

C# projects require the .Net framework and any additional dependencies you've added such as Crystal Reports.

In Visual Studio.Net, you can create a Setup and Deployment project by using any of the templates available on the New Project dialog (Other Project Types).

In addition, C# projects also support ClickOnce which brings the ease of Web deployment to Windows Forms and console applications. To get started, right click on your solution in the Solution Explorer, click Properties then select the Security tab. 

In addition, you can use any of the many free and commercially available installation packages.

Posted to KB Topic: Tool Basics
9 years ago

Code
Nothing New Since Your Last Visit
6524
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
22. C# Development Tools

Languages Focus: Development Tools

Primary development tool(s) used to develop and debug code.

C# Development Tools

Microsoft Visual C# and the full version of Microsoft Visual Studio.Net are the current primary tools. CodeGear does have C#Builder but it's not a primary tool currently and development on the tool has slowed in recent years.

Posted to KB Topic: Language Basics
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
5976
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
23. C# Empty String Check (String.IsNullOrEmpty)

The .Net framework offers a static method in the string class: String.IsNullOrEmpty.

9 years ago

Code
Nothing New Since Your Last Visit
8882
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
24. C# End of Statement (;)

C# uses a semicolon ";" as an end of statement specifier and you can put multiple statements on a single line of code if you wish as well as split a single statement into two or more code lines.

Posted to KB Topic: Language Basics
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit  
6882
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
25. C# Exception Trapping (try...catch...finally)

C# uses a try...catch...finally statement to trap for errors.

try {}
catch {}
finally {}
Posted to KB Topic: Language Basics
10 years ago, and updated 9 years ago
(1 Comments , last by Paul.L4 )

Code
Nothing New Since Your Last Visit
7692
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
26. C# File Extensions

Common source code file extensions include:

  • .SLN - Solution File. Contains solution specific information such as links to the projects within this solution.
  • .CSPROJ - C# Project File. Contains project specific information.
  • .CS - C# source file.
  • .Designer.CS - C# form file (a text resource file).
Posted to KB Topic: Tool Basics
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
6509
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
27. C# Finalizer (~ClassName)

Use a destructor to free unmanaged resources. A destructor is a method with the same name as the class but preceded with a tilde (as in ~ClassName). The destructor implicity creates an Object.Finalize method (you cannot directly call nor override the Object.Finalize method).

In C# you cannot explicitly destroy an object. Instead, the .Net Frameworks garbage collector (GC) takes care of destroying all objects. The GC destroys the objects only when necessary. Some situations of necessity are when memory is exhausted or you explicitly call the System.GC.Collect method. In general, you never need to call  System.GC.Collect.

Posted to KB Topic: OOP
9 years ago

Code

Article
Nothing New Since Your Last Visit  
13482
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
28. C# If Statement (if..else if..else)

Use () around evaluation with no "then".

Posted to KB Topic: Language Basics
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
5763
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
29. C# Inheritance (: ParentClass)

Simple syntax example of class inheritance.

Posted to KB Topic: Language Basics
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
7941
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
30. C# Inheritance-Multiple (Not Supported)

C# does not support multiple implementation inheritance. Each class can have only one parent class (a single inheritance path). In C#, you can use multiple interface usage to design in a multiple class way horizontally in a class hierarchy.

Posted to KB Topic: OOP
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
5200
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
31. C# Inlining (Automatic)

In C#, inlining is automatically done for you by the JIT compiler for all languages and in general leads to faster code for all programmers whether they are aware of inlining or not.

Posted to KB Topic: Language Details
9 years ago

Code
Nothing New Since Your Last Visit
7492
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
32. C# Interfaces (interface)

Classes and structs can inherit from interfaces in a manner similar to how classes can inherit a base class or struct, but a class or struct can inherit more than one interface and it inherits only the method names and signatures, because the interface itself contains no implementations.

class MyClass: IMyInterface
{
  public object Clone()
{
return null;
}

// IMyInterface implemented here...
}
Posted to KB Topic: OOP
10 years ago, and updated 9 years ago

Code

Article
Nothing New Since Your Last Visit
13075
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
33. C# Literals (quote)

Literals are quoted as in "Prestwood". If you need to embed a quote use a slash in front of the quote as in \"

Posted to KB Topic: Language Basics
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
7052
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
34. C# Logical Operators

Same as C++ and Java. C# logical operators:

& and, as in this and that No Short Circuit
&& and, as in this and that short circuits
| or, as in this or that No Short Circuit
|| or, as in this or that short circuits
! Not, as in Not This
^ either or, as in this or that but not both

Posted to KB Topic: Language Basics
9 years ago

Code
Nothing New Since Your Last Visit
8506
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
35. C# Member Field

In C# you can set the visibility of a member field to any visibility: private, protected, public, internal or protected internal.

You can intialize a member field with a default when declared. If you set the member field value in your constructor, it will override the default value.

Finally, you can use the static modifier (no instance required) and readonly modifier (similar to a constant).

Posted to KB Topic: OOP
9 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit  
7529
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
36. C# Member Method

In C# you can set the visibility of a member field to any visibility: private, protected, public, internal or protected internal. You can intialize a member field with a default when declared. If you set the member field value in your constructor, it will override the default value. Finally, you can use the static modifier (no instance required) and readonly modifier (similar to a constant).

Posted to KB Topic: OOP
10 years ago, and updated 9 years ago
(1 Comments , last by KalaP.Bros.K )

Code

Article
Nothing New Since Your Last Visit
11098
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
37. C# Member Modifiers

The method modifiers are abstract, extern, new, partial, sealed, virtual, and override. Specify C# member modifiers as follows:

abstract SomeMethod() {..}

The field modifiers are const, readonly, static, volatile. Specify field modifiers as follows:

readonly int MyAge;

Posted to KB Topic: OOP
9 years ago

Code
Nothing New Since Your Last Visit
6799
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
38. C# Member Property (no (), get, set)

In C#, parens indicate a method and the lack of parens indicate a property. You use special get and set methods to both get and set the values of properties. For a read-only property, leave out the set method. The value keyword is used to refer to the member field. Properties can make use of any of the access modifiers (private, protected, etc). It is common to use a lowercase member names for member fields ("name" in our example) and uppercase properties to manage member fields ("Name" in our example).

Posted to KB Topic: OOP
10 years ago, and updated 9 years ago

Code

Article
Nothing New Since Your Last Visit  
14243
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
39. C# Multiple Line Comment (// or /* */)

Commenting Code
C# uses "//" for a single line comment and /* */ for a multiple line comment.

Posted to KB Topic: Tool Basics
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
7799
Hits

C# (Visual C# & VS.Net)

Stephen Berry
40. C# Null-Coalescing Operator: ??

The null-coalescing operatior ?? is used to assign a default value for nullable value types or reference types. This operator prevents exceptions from being thrown when trying to assign a nullable type to a non-nullable type.

For example, this code will throw an exception.

int? x = null;
int y = x;

However, this code will assign the default value of -1 to y:

int? x = null;
int y = x ?? -1;
Posted to KB Topic: Language Basics
10 years ago, and updated 9 years ago
(1 Comments , last by Paul.L4 )

Definition
Nothing New Since Your Last Visit
7386
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
41. C# Overloading (implicit)

C# Overloading

  • Operator - Yes.
  • Method - Yes.
Posted to KB Topic: Language Basics
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
9931
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
42. C# Overriding (virtual, override)

Method overriding allows you to define or implement a virtual method in a parent class and then replace it in a descendant class. In C#, you specify a virtual method with the virtual keyword in a parent class and replace it in a descendant class using the override keyword.

Posted to KB Topic: OOP
10 years ago, and updated 9 years ago
(1 Comments , last by Anonymous )

Code

Article
Nothing New Since Your Last Visit
23726
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
43. C# Overview and History

Language Overview: C# is an OOP language (no global functions or variables) and is type-safe. You code using a fully OOP approach (everything is in a class).

Target Platforms: C# is most suitable for creating any type of application that runs on the .Net platform. This includes desktop business applications using WinForms and websites using WebForms.

Posted to KB Topic: Tool Basics
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
5524
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
44. C# Parameters

Defining
In C# the data type of each parameter must be specified, even if adjacent parameters are of the same type.

Posted to KB Topic: Language Basics
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
6052
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
45. C# Partial Classes (partial)

C# uses the keyword partial to specify a partial class. All parts must be in the same namespace.

A partial class, or partial type, is a class that can be split into two or more source code files and/or two or more locations within the same source file. Each partial class is known as a class part or just a part. Logically, partial classes do not make any difference to the compiler. The compiler puts the class together at compile time and treats the final class or type as a single entity exactly the same as if all the source code was in a single location.

You can use them for many things including to separate code generator code, organize large classes, divice a class up so you can split ownwership among multiple developers, have different versions of the same class, and to utilize multiple languages with a single class.

Posted to KB Topic: OOP
9 years ago, and updated 9 years ago

Code

Article
Nothing New Since Your Last Visit  
24921
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
46. C# Pointers

Although pointer data types in C# coding are less important than in other languages such as C++, C# does support developer defined pointers. Use the * operator to declare a pointer data type. Use the & operator to return the current address of a variable.

In .Net managed coding the use of pointers is not safe because the garbage collector may move memory around. To safely use pointers, use the unsafe keyword.

C++/CLI has more extensive support for pointers than C#. If you have needs that go beyond what C# offers, you can code in C++/CLI and add it to your project.

Posted to KB Topic: Language Details
9 years ago

Code
Nothing New Since Your Last Visit
7662
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
47. C# Polymorphism

C# supports the following types of polymorphism:

Posted to KB Topic: OOP
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
7406
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
48. C# Prevent Derivation (sealed)

With C#, use the sealed keyword to prevent a class from being inherited from and to prevent a method from being overridden.

A method marked sealed must override an ancestor method. If you mark a class sealed, all members are implicitly not overridable so the sealed keyword on members is not legal.

Posted to KB Topic: OOP
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
6109
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
49. C# Report Tools Overview

For WebForm applications the client target is the browser (a document interfaced GUI), a common solution is to simply output an HTML formatted page with black text and a white background (not much control but it does work for some situations). For WinForm applications, Crystal Reports is still a popular choice with C# developers because it has been bundled with many Microsoft products, it's overall popularity, and compatibility with many different development tools.

Posted to KB Topic: Tool Basics
10 years ago, and updated 10 years ago
(1 Comments , last by Anonymous )

Code
Nothing New Since Your Last Visit
8787
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
50. C# Self Keyword (this)

To refer to the current instance of a class, use the this keyword. The this keyword provides a way to refer to the specific instance in which the code is currently executing. It is particularly useful for passing information about the currently executing instance.

The this keyword is also used as a modifier of the first parameter of an extension method.

You cannot use this with static method functions because static methods do not belong to an object instance. If you try, you'll get an error.

Posted to KB Topic: OOP
9 years ago
(4 Comments , last by Mike.B3 )

Code
Nothing New Since Your Last Visit
19589
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
51. C# Static Members (static)

C# supports both static members and static classes using the static keyword. You can add a static method, field, property, or event to an existing class. Also, you can designate a class as static and the compiler will ensure all members in that class are static. You can add a constructor to a static class to initialize values.

The CLR automatically loads static classes with the program or namespace.

Posted to KB Topic: OOP
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
7934
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
52. C# String Concatenation (+)

C# String Concatenation

C# performs implicit casting of numbers to strings. To concatenate two strings, a string to an integer, or a string to a floating point number, use the + operator. For example, to convert a floating point number to a string just concatenate an empty string to the number as in "" + 3.2.

Alternatively, you can use the System.Text.StringBuilder class which frequently but not always provides faster code.

Posted to KB Topic: Tool Basics
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
6507
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
53. C# Substring

C# Substring

Above returns "abcd" on a string literal. You can, of course, use VarName.Substring(0, 4).

Posted to KB Topic: Language Basics
10 years ago

Code
Nothing New Since Your Last Visit
8755
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
54. C# Unary Operators

An operation with only one operand (a single input). The following are the C# unary operators: +, -, !, ~, ++, --, true, or false.

Posted to KB Topic: Language Basics
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
8024
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
55. C# Variables (Int16 x=0;)

C++, Java, and C# all use C-like variable declaration.

C# has C-like variable declaration and although variables are case sensitive, VS.Net will auto-fix your variable names to the defined case.

C# offers many variable types. Some common types used include short, intlong, float, double, decimal, Int16, UInt16, Int32, Int64, string, and bool.

You can also specify the value when you declare a variable as in:

String FirstName = "Mike";
String LastName = "Prestwood";
Int16 Age = 42;
Posted to KB Topic: Tool Basics
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
8181
Hits

C# (Visual C# & VS.Net)

Adam Lum
56. Changing the Trust Level in your ASP.NET Web Applications

To restrict what an ASP.NET application can and cannot access and to provide an additional level of application isolation in a hosted environment, access security can be used. You do this by configuring the element in the machine-level Web.config file located in the following folder: %windir%\Microsoft.NET\Framework\{version}\CONFIG.

Posted to KB Topic: WebForms Coding Tasks
12 years ago, and updated 9 years ago
(25 Comments , last by rrah.r )

KB Post
Nothing New Since Your Last Visit
50893
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
57. Coding for Application Virtualization How do I take advantage of Application Virtualization in the application I'm coding?
10 years ago, and updated 10 years ago

FAQ
Nothing New Since Your Last Visit
12960
Hits

C# (Visual C# & VS.Net)

Bryan Valencia
58. Consuming an RSS feed in ASP.NET

Using this quickie code snippet, you can attach an ASP:Gridview  to an external RSS Feed.

All you need to accomplish this is the URL of a usable feed.

Posted to KB Topic: WebForms Coding Tasks
8 years ago
(1 Comments , last by Louis.M )

Code
Nothing New Since Your Last Visit
17701
Hits

C# (Visual C# & VS.Net)

Adam Lum
59. C-Sharp Iterators, using yield

A quick example to demonstrate the yield keyword in the .NET Framework

Posted to KB Topic: Language Details
11 years ago, and updated 9 years ago

KB Post
Nothing New Since Your Last Visit
9298
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
60. CSharp Language Specification (C#) http://msdn.microsoft.com/en-us/library/aa664628(VS.71).aspx
Posted to KB Topic: Language Basics
10 years ago

Link
Nothing New Since Your Last Visit
5230
Hits

C# (Visual C# & VS.Net)

Daniel Fought
61. Delegate A Delegate is a variable that references a method.
10 years ago

Definition
Nothing New Since Your Last Visit
8542
Hits

C# (Visual C# & VS.Net)

Adam Lum
62. Deploying your .NET Application with ClickOnce (quick tutorial) A basic introduction to deploying an application using Visual Studio .NET 2005's ClickOnce
11 years ago, and updated 9 years ago
(1 Comments , last by mprestwood )

KB Post
Nothing New Since Your Last Visit
40354
Hits

C# (Visual C# & VS.Net)

khemebuen
63. Extension Methods in C#

Add new methods to predefined types and objects with extension methods (no need to recompile the base code).  To use this extension, all i have to do is include the  namespace ExtensionExample.

Posted to KB Topic: OOP
9 years ago, and updated 9 years ago

Blog
Nothing New Since Your Last Visit
6243
Hits

C# (Visual C# & VS.Net)

Bryan Valencia
64. FileUpload

Demonstrates the code required to retreive and store a file uploaded via an ASP FileUpload object.  Assumes you have a web form with a FileUpload, a button, and a label control.  Also, this example stores the file uploaded into a folder named "Uploads" which is assumed to pre-exist.

Posted to KB Topic: WebForms Coding Tasks
10 years ago, and updated 10 years ago

Code
Nothing New Since Your Last Visit
6039
Hits

C# (Visual C# & VS.Net)

Wes Peterson
65. Free E-Book on C# .NET Essentials This is the "Chapter Zero" you've been missing.
10 years ago

Download
Nothing New Since Your Last Visit
10312
Hits

C# (Visual C# & VS.Net)

Bryan Valencia
66. Get all components in an ASPX page recursively

Retrieves an array of all the components of any given type within a starter control (such as a page, table, panel, etc.)  This routine is recursive and will keep iterating down until all the embedded components are found.

This C# code can be invoked to produce an array as  follows:

CheckBox[] myCheckboxes = GetAllCheckboxes(Table1);
Posted to KB Topic: WebForms Coding Tasks
10 years ago, and updated 9 years ago
(2 Comments , last by Anonymous )

Code
Nothing New Since Your Last Visit
9456
Hits

C# (Visual C# & VS.Net)

Stephen Berry
67. Get UserID using ASP.NET Built-in Membership

How do you resolve the UserID of a user when using ASP.NET 2.0's built in Membership utility?

Posted to KB Topic: WebForms Beginners Corner
10 years ago, and updated 9 years ago

FAQ
Nothing New Since Your Last Visit
18714
Hits

C# (Visual C# & VS.Net)

Bryan Valencia
68. Getting Website Root Directory in C# ASP.NET

This code shows how to ask the webserver where the site's root directory is, and how to convert a relative path (like /Uploads) to the full filesystem path.  This will work across environments (i.e. Development/QA/Production).

Posted to KB Topic: WebForms Coding Tasks
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
16910
Hits

C# (Visual C# & VS.Net)

Wes Peterson
69. Great Visual Studio Training Resource If you've been around computing for any length of time, you know you can quickly spend a lot of money on those $60, five-pound reference books. For just ten dollars more, you can get your hands on over 500 great training videos for Visual Studio .NET.
11 years ago

Blog
Nothing New Since Your Last Visit
7085
Hits

C# (Visual C# & VS.Net)

Bryan Valencia
70. How to open a URL in a pop-up window. Every now and then you want a link to open not only in a new browser, but you may want to give the new window the appearance of a pop-up window. This ASP/Javascript method gives you a lot of control and is easy to figure out and implement.
Posted to KB Topic: WebForms Coding Tasks
10 years ago, and updated 9 years ago
(1 Comments , last by Wes )

KB Post
Nothing New Since Your Last Visit
48366
Hits

C# (Visual C# & VS.Net)

Wes Peterson
71. MVC Coming to ASP .NET The Model/View/Controller architecture is popular in windows desktop applications. Soon it will come to ASP .NET, as well.
Posted to KB Topic: WebForms Coding Tasks
10 years ago

News
Nothing New Since Your Last Visit
5509
Hits

C# (Visual C# & VS.Net)

Stephen Berry
72. Nullable Type Nullable types are instances of System.Nullable(T). A Nullable type can represent any of the normal values for its value type or it can be assigned the value null. This is useful when dealing with databases that may have types that do not have a value.
Posted to KB Topic: Language Basics
10 years ago

Definition
Nothing New Since Your Last Visit
7943
Hits

C# (Visual C# & VS.Net)

Bryan Valencia
73. Programattically Adding Content to Web Pages in C# Visual web developer offers a few different ways to add dynamic content to a web page. This will help you choose which one is right for your application. In General, there are Data-Aware components, Labels, and PlaceHolders.
Posted to KB Topic: WebForms Coding Tasks
10 years ago

Article
Nothing New Since Your Last Visit
7504
Hits

C# (Visual C# & VS.Net)

Daniel Fought
74. Reference Data type variables

Variables that only contain a reference to the values. Reference data type variables only contain a reference to it's constituent value.  Reference data types include objects and strings.  Assignment of one reference type variable to another copies the reference, thus changes to the values in one variable changes the values in the other.

10 years ago, and updated 9 years ago

Definition
Nothing New Since Your Last Visit
8335
Hits

C# (Visual C# & VS.Net)

Bryan Valencia
75. Sending email from C#.NET in 5 lines of code.

First, you must add the System.Net.Mail namespace to your project. There are 2 objects we use to send the email, a MailMessage, and an SMTPClient.

This code works from C# projects or from ASP.NET projects. Make sure your mail server is set to relay messages for whoever might be sending the message. In my case my webserver is sending through my exchange server so I had to tell exchange to relay for my webserver.

Posted to KB Topic: WebForms Coding Tasks
10 years ago

Code
Nothing New Since Your Last Visit
6477
Hits

C# (Visual C# & VS.Net)

Daniel Fought
76. Struct A value type used to encapsulate a small set of related data.
10 years ago, and updated 10 years ago

Definition
Nothing New Since Your Last Visit
7371
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
77. The Official Microsoft ASP.Net Site http://www.asp.net/
Posted to KB Topic: WebForms Coding Tasks
10 years ago

Link
Nothing New Since Your Last Visit
6399
Hits

C# (Visual C# & VS.Net)

Bryan Valencia
78. Using a Legacy Windows DLL in ASP.NET

This article will show how to access a function in a legacy COM dll from a ASP.NET web page. By legacy I mean a dll that is not a .NET managed code dll (a Win32 DLL). 

Posted to KB Topic: WebForms Coding Tasks
9 years ago

KB Post
Nothing New Since Your Last Visit
9815
Hits

C# (Visual C# & VS.Net)

Bryan Valencia
79. Using GenericIdentity for Cross Platform Authentication in the .NET framework

When designing a WinForms application, the most straightforward way to authenticate a user is using NTLM or Active Directory using WindowsIdentity.GetCurrent. Over the Internet, you can use the whole ASP.Net security setup with Membership.GetUser. The GenericPrincipal object works well when you deploy to a mixed web/WinForms environment. See new GenericIdentity.

Posted to KB Topic: WebForms Coding Tasks
9 years ago

KB Post
Nothing New Since Your Last Visit
13169
Hits

C# (Visual C# & VS.Net)

Wes Peterson
80. Using Win32 DLLs in .NET

Can I use a Win32 DLL in my Visual Studio.Net application?

Posted to KB Topic: WinForms
11 years ago

FAQ
Nothing New Since Your Last Visit
12297
Hits

C# (Visual C# & VS.Net)

Daniel Fought
81. Value Data type variables A Value data type variable contains values.
10 years ago

Definition
Nothing New Since Your Last Visit
8008
Hits

C# (Visual C# & VS.Net)

Mike Prestwood
82. VB Classic Prevent Derivation (Not Supported)

VB Classic supports a form of single level inheritance where you, in essence, create an abstract class and then implement it in one or more classes that inherit from the abstract class. However, you cannot have any further descendant classes so "prevent derivation" is implemented by design of this simple inheritance model.

Posted to KB Topic: OOP
10 years ago, and updated 9 years ago

Code
Nothing New Since Your Last Visit
5159
Hits

C# (Visual C# & VS.Net)

Icon Legend:
Recent or not:
- Recent activity (within last two weeks).
- No activity last two weeks.
 Since your last logged visit:
- New to you or updated since your last visit (sign in now to activate).
- NOT new to you since your last visit (sign in now to activate).

New C# (Visual C# & VS.Net) Knowledge Base Post...

Share your knowledge with the WORLD! In addition to adding comments to existing posts, you can post knowledge you've acquired. We welcome full articles (intro with screen shots), general posts (shorter), and tidbits (tips, FAQs, definitions, etc.).

Post New...

Tidbit Post: Short Flashcard FAQ Definition Quick Tip Code Snippet
Longer Post: Full Article General Post File Link Error News
Other: Blog Topic
Or, if YOU have a question...
  C# (Visual C# & VS.Net) Message Board
-
   Contact Us!
 
PrestwoodBoards.com was developed and is maintainted by me. Do you have a question or suggestion? Do you see a problem? Contact me now. My goal is to build an ad-free and spam-free source of I.T. information with many contributers (ok to promote your website/company in your bio). Yes, my company Prestwood IT Solutions is mentioned in my bio which shows with every post, but you can contribute and promote your pet project too!

2,219 People Online Now!!  
Sign In to see who's online now!  Not a member? Join now. It's free!
Show more stats...


©1995-2018 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech