Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Using Static Method in a Class
WhatsApp
Ujjwal Patel
Jan 19
2015
1.2
k
0
0
Program.cs
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
namespace
CustomerOrders
{
class
Program
{
static
void
Main(
string
[] args)
{
Items it = Items.getItem();
//here we are using items.getitem to get the method
Console.WriteLine(
"Name for item is: {0} and item id is {1}"
, it.itemname, it.itemid);
Console.ReadKey();
}
}
}
Items.cs
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
namespace
CustomerOrders
{
class
Items
{
public
int
itemid {
get
;
set
; }
public
string
itemname {
get
;
set
; }
public
static
Items getItem()
{
var newitem =
new
Items() { itemid = 101, itemname =
"Ujjwal Patel"
};
return
newitem;
}
}
}
C#
Static Method
Class
Up Next
Using Static Method in a Class