Skip to content

Instantly share code, notes, and snippets.

@abbas-oveissi
abbas-oveissi / gist:4987020
Last active February 28, 2020 14:44
sample C# code for socket
void drawSelection(Canvas canvas, int startChar, int endChar, int line) {
Rect rect = getTextRect(line);
float startX = layout.getPrimaryHorizontal(startChar );
float endX = 0;
int maxPosLine = layout.getLineEnd(line);
@abbas-oveissi
abbas-oveissi / gist:4987032
Last active December 13, 2015 22:49
sample C# code for socket
IPAddress ip = new IPAddress(new byte[] { 127, 0, 0, 1 });
IPAddress ip = IPAddress.Parse("127.0.0.1");
@abbas-oveissi
abbas-oveissi / gist:4987037
Created February 19, 2013 15:48
sample C# code for socket
IPAddress ip = IPAddress.Parse("127.0.0.1");
IPEndPoint iEp = new IPEndPoint(ip, 12345);
@abbas-oveissi
abbas-oveissi / gist:4987045
Created February 19, 2013 15:48
sample C# code for socket
Socket socket = new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp);
@abbas-oveissi
abbas-oveissi / gist:4988183
Created February 19, 2013 17:53
sample C# code for Value vs Reference Types
struct Point
{
private int x, y; // private fields
public Point (int x, int y) // constructor
{
this.x = x;
this.y = y;
}
@abbas-oveissi
abbas-oveissi / gist:4988219
Created February 19, 2013 17:55
sample C# code for Value vs Reference Types
Point p1 = new Point(); // Point is a *struct*
Form f1 = new Form(); // Form is a *class*
@abbas-oveissi
abbas-oveissi / gist:4988233
Created February 19, 2013 17:56
sample C# code for Value vs Reference Types
Form f1; // Allocate the reference
f1 = new Form(); // Allocate the object
@abbas-oveissi
abbas-oveissi / gist:4988241
Created February 19, 2013 17:57
sample C# code for Value vs Reference Types
Point myPoint = new Point (0, 0); // a new value-type variable
Form myForm = new Form(); // a new reference-type variable
Test (myPoint, myForm); // Test is a method defined below
void Test (Point p, Form f)
{
p.X = 100; // No effect on MyPoint since p is a copy
f.Text = "Hello, World!"; // This will change myForm’s caption since
// myForm and f point to the same object
f = null; // No effect on myForm
@abbas-oveissi
abbas-oveissi / gist:4988253
Created February 19, 2013 17:58
sample C# code for Value vs Reference Types
Point myPoint = new Point (0, 0); // a new value-type variable
Form myForm = new Form(); // a new reference-type variable
Test (ref myPoint, ref myForm); // pass myPoint and myForm by reference
void Test (ref Point p, ref Form f)
{
p.X = 100; // This will change myPoint’s position
f.Text = “Hello, World!”; // This will change MyForm’s caption
f = null; // This will nuke the myForm variable!
}
@abbas-oveissi
abbas-oveissi / gist:4988716
Created February 19, 2013 18:48
sample C# code for Value vs Reference Types
Point p2 = p1;
Form f2 = f1;