|
-
May 11th, 2004, 06:22 PM
#1
MyBase equivalent in C#? and others?
well I get a better response in the Vb.net section hence I posted this here. It's a question that the vb people shuold answer anyways
so what is MyBase in C#?I wanna use MyBase.New...
Another q, what's MyClass in C#?
also, if I wanna call an overloaded new constructor from another constructor, how do I do it? (ie, new (blah, blah) )
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
May 11th, 2004, 06:40 PM
#2
The MyBase equivalent in C# is base.
You would do constructor chaining like this...
Code:
public class Test
{
public Test(): this(1)
{
//...
}
public Test(int x)
{
//...
}
}
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
May 11th, 2004, 06:43 PM
#3
Originally posted by crptcblade
The MyBase equivalent in C# is base.
You would do constructor chaining like this...
Code:
public class Test
{
public Test(): this(1)
{
//...
}
public Test(int x)
{
//...
}
}
hmm thanks... what is that : this(1) doing in front of the constructor ?
yeah apparently base "acts" differently from MyBase of VB. You can use MyBase.NEW in vb anyways here's how I'm calling the constructor withing another constructor and it apparently works. It this the right way though?:
Public Test()
{
new Text (3);
}
edit:hmm I'm gussing this(1) is calling the constructor, uuh but it's weird because when I do it the stupid Intellisense doesnt show up, but when I use new() it does show up
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
May 11th, 2004, 07:17 PM
#4
Originally posted by MrPolite
It this the right way though?:
Public Test()
{
new Text (3);
}
That doesn't work for me. Try it...
Code:
/* ... Form code... */
{
private void Form1_Load(object sender, System.EventArgs e)
{
Test t = new Test();
MessageBox.Show(t.X.ToString());
}
}
public class Test
{
private int _x;
public int X
{
get { return _x; }
}
public Test()
{
new Test(1);
}
public Test(int x)
{
_x = x;
}
}
Instead of returning 1 like you would think, it returns 0. That's because
public Test()
{
new Test(1);
}
simple creates a new Test object and it simpley goes away.
The first way is the correct way.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
May 11th, 2004, 07:19 PM
#5
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
May 11th, 2004, 07:36 PM
#6
hmm so one more question. Does the constructor chaining occure AFTER you are done with the current constructor?
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
May 11th, 2004, 07:46 PM
#7
Code:
public Test() : this(1)
{
System.Diagnostics.Debug.WriteLine("1");
}
public Test(int x)
{
System.Diagnostics.Debug.WriteLine("2");
_x = x;
}
Results in :
2
1
So the constructor that is called from the constructor executes first, then the original constructor's code is executed.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
May 11th, 2004, 11:05 PM
#8
hmm interesting. So I'm puzzled, what if I want to do something like this!
public Test()
{
int someNum;
// compute someNum ....
// NOW call the other constructor with the someNum value
// Test (someNum)
}
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
May 13th, 2004, 12:06 AM
#9
ok apparently what I asked in the last post isnt possible. But is this possible:
public Test():base (99999)
{}
I want to call this (1) after calling the base constructor. How would I do that?
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
May 13th, 2004, 06:06 AM
#10
You can't make two constructor calls. You either deall with the call, pass the call to another overload of your constructor, or pass the call to the base class.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
May 13th, 2004, 06:25 PM
#11
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|