File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
samples/snippets/csharp/VS_Snippets_VBCSharp/CsProgGuideTypes/CS Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -109,6 +109,42 @@ static void Wrap()
109
109
}
110
110
}
111
111
112
+
113
+ //-------------------------------------------------------------------------
114
+ class BoxingValueCopy
115
+ {
116
+ static void Main ( )
117
+ {
118
+ //<Snippet16>
119
+ // Create an int variable
120
+ int i = 123 ;
121
+
122
+ // Box the value type into an object reference
123
+ object o = i ; // boxing
124
+
125
+ // Display the initial values
126
+ Console . WriteLine ( $ "Value of i: { i } ") ;
127
+ Console . WriteLine ( $ "Value of boxed object o: { o } ") ;
128
+
129
+ // Modify the original value type
130
+ i = 456 ;
131
+
132
+ // Display the values after modification
133
+ Console . WriteLine ( "\n After changing i to 456:" ) ;
134
+ Console . WriteLine ( $ "Value of i: { i } ") ;
135
+ Console . WriteLine ( $ "Value of boxed object o: { o } ") ;
136
+
137
+ // Output:
138
+ // Value of i: 123
139
+ // Value of boxed object o: 123
140
+
141
+ // After changing i to 456:
142
+ // Value of i: 456
143
+ // Value of boxed object o: 123
144
+ //</Snippet16>
145
+ }
146
+ }
147
+
112
148
//-------------------------------------------------------------------------
113
149
class TestBoxing
114
150
{
You can’t perform that action at this time.
0 commit comments