Click here to Skip to main content
16,005,037 members
Home / Discussions / C#
   

C#

 
GeneralRe: Constructor of Structs. Pin
SPanicker*19-Mar-08 20:07
SPanicker*19-Mar-08 20:07 
GeneralRe: Constructor of Structs. Pin
mmikey719-Mar-08 4:53
mmikey719-Mar-08 4:53 
GeneralRe: Constructor of Structs. Pin
SPanicker*19-Mar-08 5:17
SPanicker*19-Mar-08 5:17 
GeneralRe: Constructor of Structs. Pin
SPanicker*19-Mar-08 5:30
SPanicker*19-Mar-08 5:30 
GeneralRe: Constructor of Structs. Pin
mmikey719-Mar-08 5:50
mmikey719-Mar-08 5:50 
GeneralRe: Constructor of Structs. Pin
SPanicker*19-Mar-08 20:04
SPanicker*19-Mar-08 20:04 
GeneralRe: Constructor of Structs. Pin
mmikey719-Mar-08 21:48
mmikey719-Mar-08 21:48 
GeneralRe: Constructor of Structs. Pin
SPanicker*20-Mar-08 21:51
SPanicker*20-Mar-08 21:51 
Hi Michal,

Sorry what i meant was, I have a constructor for a (value type - declared without new keyword) struct.

This constructor cannot invoke any inbuilt functions like Console.WriteLine or user defined ones. But at the same time it can do assign values for fields. This seems quite strange.

But, the same things works well(from inside the constructor)if it is declared with the new keyword.

Pls. chk this sample code and tell me if somethngs wrong:

using System;<br />
<br />
struct newStruct<br />
{<br />
	//case 1: With struct new operator <br />
	public newStruct(int a)<br />
	{<br />
		Console.WriteLine("In newStruct");<br />
		Console.WriteLine("{0}",a);<br />
	}<br />
}<br />
struct anotherStruct<br />
{<br />
	//case : Without new operator - like a value type variable.<br />
	public int x;<br />
	public anotherStruct(int a)<br />
	{<br />
		Console.WriteLine("In newStruct");<br />
		x = a;<br />
		Console.WriteLine("{0},{1}",a,x);<br />
	}<br />
	public void method1()<br />
	{<br />
		Console.WriteLine(x);<br />
	}<br />
}<br />
<br />
class AppEntry <br />
{<br />
	<br />
<br />
	public static void Main()<br />
	{<br />
		newStruct abc = new newStruct(10);<br />
		anotherStruct def;<br />
		def.x= 250;	<br />
		def.method1();<br />
	}<br />
}


Regards,
Lenus.

GeneralRe: Constructor of Structs. Pin
mmikey721-Mar-08 3:34
mmikey721-Mar-08 3:34 
GeneralRe: Constructor of Structs. Pin
SPanicker*23-Mar-08 21:49
SPanicker*23-Mar-08 21:49 
GeneralThe C# webbrowser and Widgets Pin
aggla19-Mar-08 3:37
aggla19-Mar-08 3:37 
GeneralDns.GetHostEntry() WinXP WinVista Issue Pin
Harvey Saayman19-Mar-08 2:03
Harvey Saayman19-Mar-08 2:03 
GeneralRe: Dns.GetHostEntry() WinXP WinVista Issue Pin
Bekjong19-Mar-08 2:22
Bekjong19-Mar-08 2:22 
GeneralRe: Dns.GetHostEntry() WinXP WinVista Issue [SLOVED] Pin
Harvey Saayman19-Mar-08 2:27
Harvey Saayman19-Mar-08 2:27 
GeneralRe: Dns.GetHostEntry() WinXP WinVista Issue [SLOVED] Pin
Bekjong19-Mar-08 3:03
Bekjong19-Mar-08 3:03 
GeneralRe: Dns.GetHostEntry() WinXP WinVista Issue [SLOVED] Pin
Harvey Saayman19-Mar-08 3:06
Harvey Saayman19-Mar-08 3:06 
GeneralRe: Dns.GetHostEntry() WinXP WinVista Issue [SLOVED] Pin
Harvey Saayman19-Mar-08 3:19
Harvey Saayman19-Mar-08 3:19 
GeneralRe: Dns.GetHostEntry() WinXP WinVista Issue [SLOVED] Pin
Bekjong19-Mar-08 3:31
Bekjong19-Mar-08 3:31 
Generalcrypto stream problems Pin
Russell Jones19-Mar-08 0:52
Russell Jones19-Mar-08 0:52 
GeneralRe: crypto stream problems Pin
Ennis Ray Lynch, Jr.19-Mar-08 3:45
Ennis Ray Lynch, Jr.19-Mar-08 3:45 
GeneralRe: crypto stream problems Pin
Russell Jones19-Mar-08 4:19
Russell Jones19-Mar-08 4:19 
GeneralRe: crypto stream problems Pin
Russell Jones19-Mar-08 5:51
Russell Jones19-Mar-08 5:51 
GeneralThreading concepts.. Pin
ptr2void19-Mar-08 0:45
ptr2void19-Mar-08 0:45 
GeneralRe: Threading concepts.. Pin
Laddie19-Mar-08 0:51
Laddie19-Mar-08 0:51 
GeneralRe: Threading concepts.. Pin
ptr2void19-Mar-08 1:10
ptr2void19-Mar-08 1:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.