Register for your free account! | Forgot your password?

You last visited: Today at 00:41

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[lil explanation]

Discussion on [lil explanation] within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Apr 2012
Posts: 134
Received Thanks: 30
[lil explanation]

well simply i need someone to explain more about this for me
Code:
void AccessAll(Control.ControlCollection cc)
	{
		foreach (Control c in CC)
		{
			if (c is CheckBox)
			{
				CheckBox ch = c as CheckBox;
				ch.Checked = true;
			}
			if (c.HasChildren) AccessAll(c.Controls);
		}
	}
umm it's a method who takes argument of control type , for each loop to get all the controls in cc , c is umm instance from cc ?
anyway the part i cant understand over here is this one
Quote:
CheckBox ch = c as CheckBox;
he create an instance(ch) of an instance(c) as the instance c (of controls) wont have the property checked ?
c as checkbox ?
sorry my first time to see this , thanks in advance

edit : same goes for umm "Button b = c as Button;" as c isnt a button , it's an instance of cc , so we create an instance b from buttons with type c which it's type is cc which is control ? wdf o-0 lol
DyjgK64J451Jhv0 is offline  
Old 04/14/2012, 16:01   #2
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
Ok... You seem slightly confused but I'll go ahead and explain from basic to more complex/specific terms...

#1: Everything* in C# is an object. That is why it is an object oriented programming language and that's how you should approach it...

#2: This method (AccessAll) accepts a single object of type "ControlCollection". This means it can be ANY type of controls grouped into a collection (think of a list of buttons, inputs, toggles, checkboxes, etcetc)

#3: You then iterate through each control in this collection (collection = CC)

#4: You check the type of each object iteration (each iteration = c)

#5: IF the object type is CheckBox, you cast the data to that type so you can now deal with it as a non generic object (or generic control object in this case)

Note: You are not creating a new instance, you are simply taking existing data and treating it as a different object type. Think of this like doing (int)number to force it to conform to the int data type.

You then are using iteration to deal with the fact that ControlCollections can contain OTHER ControlCollections which you would then need to iterate through (as many levels deep as required)

As for your final question.... When you modify ch, it modifies the original collection object because you are not creating a new object, simply modifying the one that already exists.


It's like saying...


Player user = Kernel.Clients[UID];
user.Name = "new Name";

If you now check Kernel.Clients[UID].Name it will be the same as user.Name
pro4never is offline  
Thanks
1 User
Old 04/14/2012, 17:09   #3
 
elite*gold: 0
Join Date: Apr 2012
Posts: 134
Received Thanks: 30
first of all thanks for replying
well about
if (c is CheckBox)
{
CheckBox ch = c as CheckBox;
ch.Checked = true;
}
u said that u create an object ch of c so u can apply changes on cuz other c may be another control and not checkbox ? or because c isnt a checkbox object and .checked property is a property of checkbox ? i guess the second one , well the most confusing part for me is "checkbox ch = c as checkbox" , why he said "c as checkbox" ?

maybe cuz u cant do the 2nd one ?
checkbox ch = new checkbox >> 1
checkbox ch = c control >> 2
checkbox ch = c as checkbox >> 3

guess ill go to read more about "as" , thanks for replying ^^
DyjgK64J451Jhv0 is offline  
Old 04/14/2012, 17:18   #4


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,126
Received Thanks: 2,518
Basically because when your itterating through the CC collection here:

Code:
foreach (Control c in CC)
c there is actually a Control object, however the Control object is just a base class that all Controls are built upon and expand. So the Checkbox is a type of Control, and what your doing with c as CheckBox is allowing you to access all the Checkbox specific methods, properties etc.

Thats the none technical explanation atleast.
Korvacs is offline  
Thanks
1 User
Old 04/14/2012, 17:38   #5
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
Quote:
Originally Posted by DyjgK64J451Jhv0 View Post
first of all thanks for replying
well about
if (c is CheckBox)
{
CheckBox ch = c as CheckBox;
ch.Checked = true;
}
u said that u create an object ch of c so u can apply changes on cuz other c may be another control and not checkbox ? or because c isnt a checkbox object and .checked property is a property of checkbox ? i guess the second one , well the most confusing part for me is "checkbox ch = c as checkbox" , why he said "c as checkbox" ?

maybe cuz u cant do the 2nd one ?
checkbox ch = new checkbox >> 1
checkbox ch = c control >> 2
checkbox ch = c as checkbox >> 3

guess ill go to read more about "as" , thanks for replying ^^
The As keyword is basically just casting between object types.


It's like saying....

Foreach(Fruit fr in Bowl)
{
if(fr is Apple)
{
Apple _apl = fr as Apple;
_apl.RemoveSeeds();
}
}


Fruit is a base type of object... (all apples are fruit but not all fruits are apples) which other object types build upon. Apple is a more specific object type which can have its own methods and variables (in addition to the basic ones assigned to all fruits). We can say 'ok we know this fruit is an apple... cause we checked, so lets treat it as an apple and then do what we want with it'.

Yay generic explanations!
pro4never is offline  
Thanks
2 Users
Old 04/14/2012, 19:15   #6
 
elite*gold: 0
Join Date: Apr 2012
Posts: 134
Received Thanks: 30
Quote:
Originally Posted by pro4never View Post
The As keyword is basically just casting between object types.


It's like saying....

Foreach(Fruit fr in Bowl)
{
if(fr is Apple)
{
Apple _apl = fr as Apple;
_apl.RemoveSeeds();
}
}


Fruit is a base type of object... (all apples are fruit but not all fruits are apples) which other object types build upon. Apple is a more specific object type which can have its own methods and variables (in addition to the basic ones assigned to all fruits). We can say 'ok we know this fruit is an apple... cause we checked, so lets treat it as an apple and then do what we want with it'.

Yay generic explanations!
i want an apple !
DyjgK64J451Jhv0 is offline  
Old 04/14/2012, 20:53   #7
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
I feel like I should have gone with...

PieManager.MakePie(_apl);

But then I'd need some other ingredients for the method.
pro4never is offline  
Thanks
1 User
Old 04/14/2012, 22:26   #8
 
InfamousNoone's Avatar
 
elite*gold: 20
Join Date: Jan 2008
Posts: 2,012
Received Thanks: 2,885
Quote:
Originally Posted by pro4never View Post
The As keyword is basically just casting between object types.


It's like saying....

Foreach(Fruit fr in Bowl)
{
if(fr is Apple)
{
Apple _apl = fr as Apple;
_apl.RemoveSeeds();
}
}


Fruit is a base type of object... (all apples are fruit but not all fruits are apples) which other object types build upon. Apple is a more specific object type which can have its own methods and variables (in addition to the basic ones assigned to all fruits). We can say 'ok we know this fruit is an apple... cause we checked, so lets treat it as an apple and then do what we want with it'.

Yay generic explanations!
This is the incorrect usage of the as keyword.
The purpose of the is keyword is to check type-safety for regular type-casting, for instance:

Code:
int num = 1337;
object obj = num;
if (obj is long)
{
	long n = (long)obj;
	// ...
}
However, checking type-safety does not have to be done with the as keyword. If an object is not of the type you are casting to null is returned, and no error will be thrown.

Code:
int num = 1337;
object obj = num;
string s = obj as string;
if (s != null)
{
	// ...
}
InfamousNoone is offline  
Thanks
1 User
Old 04/15/2012, 02:41   #9
 
Chalkie's Avatar
 
elite*gold: 0
Join Date: Nov 2008
Posts: 288
Received Thanks: 197
I like apples.
Chalkie is offline  
Old 04/15/2012, 08:04   #10
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
Quote:
Originally Posted by InfamousNoone View Post
This is the incorrect usage of the as keyword.
The purpose of the is keyword is to check type-safety for regular type-casting, for instance:

Code:
int num = 1337;
object obj = num;
if (obj is long)
{
	long n = (long)obj;
	// ...
}
However, checking type-safety does not have to be done with the as keyword. If an object is not of the type you are casting to null is returned, and no error will be thrown.

Code:
int num = 1337;
object obj = num;
string s = obj as string;
if (s != null)
{
	// ...
}

I'm well aware that if you use as on an incorrect data type you'll receive a null result... I was trying to dumb it down as best I could while at work.

I apologize for any missused terms or mistakes in the process.
pro4never is offline  
Thanks
1 User
Reply


Similar Threads Similar Threads
Need some explanation >.<
08/15/2011 - Silkroad Online - 4 Replies
It's about Ramadan Event..I'm collecting Alibaba seals but the questaion is when does the event finishes? i'm confused coz I went to sro site & it say August 2, 2011 ~ August 16, 2011 (2 weeks)..& some where down it says AliBaba Seal reward: August 23 ~ August 30, 2011 (1 week) :confused:
Need explanation
03/23/2011 - EO PServer Hosting - 2 Replies
Hello, I was trying to make something like this: when time comes then everyone will teleport to current map , when time ends then everyone teleport to main map... so first thing i did was openning action define and i found something like this //--- duty system, logger task detail---begin
Need some explanation here..
09/06/2010 - EO PServer Hosting - 9 Replies
Hi all..my server got a few problem now.. and i dont know what is the problem.. Acc server run good..also msg server run good.. and NPC server run good...But after a few minute.Msg server stop working. i have looking at error log..this what i have found.. 14:52:30 ERROR: ¡ïASSERT(!"Error action type!")¡ï in e:\tq_digital\ħÓò\reliable\src\MsgServer\MapGroup Kernel\GameAction.cpp, 1300 14:52:30 ERROR: ¡ïCHECKF(pType)¡ï in...
Need an explanation please^^
02/04/2009 - Kal Online - 13 Replies
Hello people. Long time ago I wrote a little memory scanner. A program like the normal Cheat Engines but its just a console window^^ Well when I wrote it I tried it with Kal and got what I expected: I couldnt access Kals Memory area cause of HS/KOCP or whatever. Well today I tried it again (dont even know why I tried) and well... suddenly it works. I found the max HP adress, the speed adress. And I even can change it with my little noob CE^^ No-Mana G3 speed works perfectly. Well my question,...



All times are GMT +1. The time now is 00:41.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.