TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Using Static Method in a Class
Ujjwal Patel
Jan 19
2015
Code
1.1
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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#
Class
Static Method