473,385 Members | 1,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Can I use static an override method in C#?

meomap0z1
I have this method in Student.cs :
Expand|Select|Wrap|Line Numbers
  1.  
  2. public virtual void XemThongTin()
  3.         {
  4.  
  5.             Console.WriteLine("Danh sach sinh vien: ");
  6.  
  7.         }
  8.  
then I override this method in another class which is Program.cs :
Expand|Select|Wrap|Line Numbers
  1. public override void XemThongTin()
  2.         {
  3.             Console.WriteLine("Danh sach sinh vien: ");
  4.             foreach (SinhVien sv in QuanLySinhVien.DanhSachSinhVien)
  5.             {
  6.                 Console.WriteLine("StudentID: " + sv.MMaSV);
  7.                 Console.WriteLine("Name " + sv.Name1);
  8.                 Console.WriteLine("DateOfBirth: " + sv.Birthday1);
  9.                 Console.WriteLine("Number: " + sv.Number1);
  10.                 Console.WriteLine("------*****------");
  11.             }
  12.         }
  13.  
Now I wanna call it in
static void Main(string[] args) {}
Jan 21 '20 #1

✓ answered by Ishan Shah

Yes, We can use static an override method in c#. I have tried it and I made MainClass for calling it in static void main(string[] args){}.

The Code is Following :

Expand|Select|Wrap|Line Numbers
  1. class MainClass
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             Student st=new Student();
  6.             st.XemThongTin();
  7.             Program pr=new Program();
  8.             pr.XemThongTin();
  9.             Console.ReadLine();
  10.         }
  11.  
  12.     }

2 1997
Ishan Shah
47 32bit
Yes, We can use static an override method in c#. I have tried it and I made MainClass for calling it in static void main(string[] args){}.

The Code is Following :

Expand|Select|Wrap|Line Numbers
  1. class MainClass
  2.     {
  3.         static void Main(string[] args)
  4.         {
  5.             Student st=new Student();
  6.             st.XemThongTin();
  7.             Program pr=new Program();
  8.             pr.XemThongTin();
  9.             Console.ReadLine();
  10.         }
  11.  
  12.     }
Jan 22 '20 #2
Wow, Thanks a million for your helping !!!!! You save my day, bro.
Jan 22 '20 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: javac | last post by:
for better or worse, my free time is consumed by two Java series books from Sun: Java Platform Performance, 2000, by Wilson and Kesselman Effective Java, 2001, by Bloch 1.) opinions on these...
3
by: John Bailo | last post by:
I want to name a variable in a form Move. But Move() is a method, (Control.Move) that the form inherits. Can I override a method and have a variable with the same name that I can access...
2
by: Chris Bruce | last post by:
How does one call a static C# method from an unmanaged C dll? Thanks
4
by: Lloyd Dupont | last post by:
When I want some app resources I usually write something like: MapPath(ResolveUrl("~/App_Data/MyResource")) How could I do the same thing in a static helper method? I mean MapPath & ResolveUrl...
3
by: russell | last post by:
I need to override base class method in child class. And in it overriden method call base class method. How can I do this?
13
by: Ben Voigt | last post by:
Is there any way to have an overridden method which is not callable from the assembly overridding it? A contrived example (though I want this feature, my program has nothing to do with food...
0
by: Donn Ingle | last post by:
In an unusual twist of code I have a subclass which overrides a method but it also needs to call the original method: class One: def add (self, stuff): self.stuff.append(stuff) class...
8
by: munk | last post by:
I post this a C# newbie - please bear with me :-) I have coded a small project in C#, and ran into a problem illustrated in the below minimal project cs file. I wonder how to make the following...
6
by: jake | last post by:
I think I may why this is happening but I am a little fuzzy as to what the solution should be as I am somewhat new to all of this. My simplified code that generates the error is: public static...
1
by: Rach26 | last post by:
Hello I am currently developing my masters project and am relativly new to C# I am having a problem with my Cache. In settings.settings I have placed the following after my connection setting: ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.