C# Crawler
Sagiv Hadaya is crawling in C#...just for fun





Subscribe to "C# Crawler" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

Google


Monday, August 12, 2002
 
A non blocking chat application

This is a very good article, with a depth explanations on how to build (write) a C# chat application.

what is unique, is that this application is non blocking, and teaches the secrets of C#-Sockets.

 

 

source [CSharpFriends]


6:35:39 PM    
Triple XOR

Lets implement a string reverse in C#
in most sites you will see an implementation using a recursion:
public static string Reverse(string str) 
{ 
	/*termination condition*/
	 if(1==str.Length) 
	{ 
		return str; 
	} 
	else 
	{ 
		return Reverse( str.Substring(1) ) + str.Substring(0,1); 
	} 
} 
 
but in C# Crawler, i will show you a nicer version (i think) that uses 
the old trick - triple Xor.

private string Rev(string x)

{

char[] c = x.ToCharArray (); /*convert to chararray*/

int l = x.Length -1;

 

for (int j=0;j<l;j++,l--)

{

c[j]^=c[l]; /*triple xor will */

c[l]^=c[j]; /*replace c[j] with c[i]*/

c[j]^=c[l]; /*without a temp var*/

}

string s=new string(c); /*convert back to string*/

return s;

}


6:03:56 PM    
Access Levels in C#

I have been asked about access levels avilable in C#, there are 5 of them, and could be remembered as PPIPP!!!

the top level is Public, which is no restricion.

the second one is protected, which allows access for the containing class, or lass that inherit it.

the third one is internal, which allows access only for the corrent project.

the forth one is protected internal (the only combination available), which allows access for the corrent project, or derived types derived from this class.

the last one is private, and its the most restricted one, allows access only for the containing type.

clear?


2:41:47 PM    
IExplore Pop-ups spy

...from CSharpHelp.com

Often when surfing web site, we get frustrated with all the small pop-up windows and advertisements that appear on the desktop. Well I got so frustrated with those, that I thought of writing a small application that can automatically close such windows [...] by Shripad Kulkarni


1:11:41 PM    
Things to avoid while migrating to C# (part 1)

Someone asked me, are there any things that might be confusing in c# if i was a C++ programmer?

I say yes, but i like to call it simplicity.

 

Simplicity in C# comes to break apart all the annoying things in C/C++. for example, have you ever wrote an if statement in C/C++ that looks like this:

if (x = 0) { . . . }

and wondered for days what went wrong? (if you have'nt noticed, this simple if statement actually assign x with 0, and not comparing it with 0).

In C# you cant do that, C# compiler will complain that this (x=0) statement is not a bool one, and cannot be converted to bool, which means that you must explicitly state every if/while/... as bool, that cannot be converted to other types.

Another thing is Switch statements...a very common place for fall downs;

In C/C++ something like this is ok:

switch(x) {

case 1:

case 2:

        [...something...]

        break;

case 3:

case 4:

        [...something...]

        break;

}

 

What it means is that case 1 and 2 are "fall through". when x is 1, the switch statement will fall through 2 and up until it hit the break.

in C# every case has a break, this line on code (6 lines if you will) will cause the compiler of c# to generate a break after EVERY case. and if we wanted fall through? well consider this:

switch(x) {

case 1:

         goto case 2;

case 2:

        [...something...]

        break;

case 3:

        goto case 4;

case 4:

        [...something...]

        break;

}

 

to gain the same effect.

(c)sagiv

I will be happy to get comments this line of articles.

 


10:30:32 AM    
Why does C# holds 'Ref' and 'Out' all together?

Have you asked yourself that?

Well i have, and i have the answer for you: Ref and Out are two seperate animals, they both might sound the same, but they eat difrerantly :)

When a function is set to have one or more of its variables as ref, it means that the caller MUST assign a value to that ref variable, and the callee will change it (does not have to). making a long sentance short - ref means that the caller must assign a value (or the compiler will for you) before calling the function.

On the other hand, an Out parameter means that the caller is not required to assign a value to that out variable, but the callee must ,and will, assign a value before returning the variable to the caller.


9:48:42 AM    



Click here to visit the Radio UserLand website. © Copyright 2002 Sagiv Hadaya.
Last update: 9/3/2002; 3:12:12 PM.
August 2002
Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Jul   Sep

C#_Help

C#_Organization

DEVX

Google

Microsoft

CSharp_Friends