Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,948 questions

51,890 answers

573 users

How to use struct in C#

1 Answer

0 votes
using System;

public struct Point {
    public int X;
    public int Y;

    public Point(int x, int y) => (X, Y) = (x, y);

    public override string ToString() => $"({X}, {Y})";
}

public class Program
{
    public static void Main()
    {
        var p1 = new Point(4, 8);
        var p2 = p1;
        
        p2.X = 100;
        p2.Y = 200;
        Console.WriteLine(p1);
        Console.WriteLine(p2);

        f(p2);
        
        Console.WriteLine(p1);
        Console.WriteLine(p2);
    }

    private static void f(Point p) {
        p.X = 333;
        p.Y = 555;
        Console.WriteLine(p);
    }
}



/*
run:

(4, 8)
(100, 200)
(333, 555)
(4, 8)
(100, 200)

*/

 



answered Nov 22, 2020 by avibootz

Related questions

1 answer 92 views
1 answer 145 views
145 views asked Dec 15, 2020 by avibootz
1 answer 121 views
1 answer 126 views
126 views asked Dec 15, 2020 by avibootz
1 answer 128 views
128 views asked Nov 22, 2020 by avibootz
1 answer 150 views
1 answer 117 views
117 views asked Apr 27, 2017 by avibootz
...