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,900 questions

51,831 answers

573 users

How to use static property in C#

2 Answers

0 votes
using System;

class Example
{
    static int _score;
    
    public static int Score {
        get {
            _score++;
            return _score;
        }
    }
}

class Program
{
    static void Main() {
        Console.WriteLine(Example.Score);
        Console.WriteLine(Example.Score);
        Console.WriteLine(Example.Score);
        Console.WriteLine(Example.Score);
        Console.WriteLine(Example.Score);
    }
}


 
/*
run:
    
1
2
3
4
5
  
*/

 



answered Aug 22, 2018 by avibootz
edited May 7, 2024 by avibootz
0 votes
using System;
 
class Student
{
    private static string _name;
 
    public static string Name {
        get {
            return _name;
        }
        set {
            _name = value;
        }
    }
}
 
class Program
{
    static void Main(string[] args)
    {
        Student.Name = "Tom";
         
        Console.WriteLine(Student.Name);
    }
}
 
 
 
/*
run:
 
Tom
 
*/

 



answered May 7, 2024 by avibootz

Related questions

1 answer 177 views
1 answer 184 views
1 answer 121 views
1 answer 105 views
105 views asked Apr 5, 2019 by avibootz
2 answers 187 views
187 views asked Aug 25, 2018 by avibootz
1 answer 200 views
...