How to declare, set values and print a struct in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        struct Test
        {
            public int n;
            public double d;
            public bool b;
        };

        static void Main(string[] args)
        {
            Test t;

            t.n = 100;
            t.d = 3.14;
            t.b = true;

            Console.WriteLine(t.n);
            Console.WriteLine(t.d);
            Console.WriteLine(t.b);
        }
    }
}

/*
run:
   
100
3.14
True

*/

 



answered Jan 18, 2017 by avibootz

Related questions

2 answers 251 views
1 answer 111 views
1 answer 141 views
2 answers 211 views
...