System.Object
class) is the ultimate base class for all data types.
The object types can be assigned values of any other types.
However, before assigning values, it needs type conversion.
When a value type is converted to object type, it is called boxing and on the other hand, when an object type is converted to a value type, it is called unboxing:
object obj; obj = 100; // this is boxingDynamic Types
dynamic <variable_name> = value;
; e.g.,
dynamic d = 20;String Types
System.String
class) allows you to assign any string values to a variable.
The value for a string type can be assigned using string literals in two forms: quoted and @quoted.
For example,
String str = "Tutorials Point";A @quoted string literal looks as follows −
@"Tutorials Point";Pointer Types
type* identifier;
.
For example,
char* cptr; int* iptr;An Example
A string is enclosed by double quotes. The example shows string concatenation by using the operator ‘+’. The IF statement decides which greeting is to be printed based on the checked radio button. Two radio buttons, four labels (one for the output), one textbox, and one button are used for this example. |
using System; using System.Windows.Forms; namespace WindowsFormsApp4 { public partial class Form1 : Form { public Form1( ) { InitializeComponent( ); } private void Button_Click( object sender, EventArgs e ) { string greeting; if ( radioButton1.Checked ) greeting = "Good morning, "; else greeting = "Good afternoon, "; result.Text = greeting + user.Text + "!"; } } } |