.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Demonstrate the ByTwos interface

Posted By:SanthoshNathan       Posted Date: November 02, 2010    Points: 15    Category: Visual Studio    URL: http://www.dotnetspark.com  

Demonstrate the ByTwos interface
 

using System; 

public interface ISeries 
  int getNext()// return next number in series 
  void reset()// restart 
  void setStart(int x)// set starting value 
}

// Implement ISeries. 
class ByTwos : ISeries 
  int start; 
  int val; 
 
  public ByTwos() { 
    start = 0
    val = 0
  }  
 
  public int getNext() { 
    val += 2
    return val; 
  
 
  public void reset() { 
    val = start; 
  
 
  public void setStart(int x) { 
    start = x; 
    val = start; 
  
}

// Demonstrate the ByTwos interface. 
 
public class SeriesDemo 
  public static void Main() { 
    ByTwos ob = new ByTwos()
 
    for(int i=0; i < 5; i++
      Console.WriteLine("Next value is " 
                         ob.getNext())
 
    Console.WriteLine("\nResetting")
    ob.reset()
    for(int i=0; i < 5; i++
      Console.WriteLine("Next value is " 
                         ob.getNext())
 
    Console.WriteLine("\nStarting at 100")
    ob.setStart(100)
    for(int i=0; i < 5; i++
      Console.WriteLine("Next value is " 
                         ob.getNext())
  
}


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend