Showing posts with label MS Visual Studio. Show all posts
Showing posts with label MS Visual Studio. Show all posts

18 August 2016

How to replace AdMediator control with AdControl in UWP

If you developed application in Windows App Studio for Universal Windows 10 platform and generate source code for further developing in Visual Studio, than :

* Install Microsoft Store Services SDK

Open MS Visual Studio and working project, than :

* remove refence on Microsoft Advertising Universal SDK
* open Layouts\Controls\AdvertisingControl.xaml
* replace

xmlns:Universal="using:Microsoft.AdMediator.Universal"
with
xmlns:Universal="using:Microsoft.Advertising.WinRT.UI"

* replace
<Universal:AdMediatorControl
with
<Universal:AdControl

Select AdControl in Design window and enter these Miscellaneous properties :
* AdUnitId
* ApplicationId
which you prepared in Windows Dev Center - Monetization section

Rebuild project and thats it.




22 November 2015

Windows AdDuplex NuGet support

The best way to integrate AdDuplex into your project is through NuGet system, and not Visual Studio Gallery on MSDN.

This prevent Visual Studio Designer from Unhandled Exceptions.

So, if you already added Reference on installed AdDuplex support from Visual Studio Gallery on MSDN, remove it, and add corresponding NuGet packages for AdDuplex support.

Then in Windows 10 Universal project:

Add a namespace declaration to your page
xmlns:adduplex="using:AdDuplex"

Add an AdControl to your page:
< adduplex:AdControl AdUnitId="xxxxxx" AppKey="xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" />

Then in Windows 8.1 Store project:

Add a namespace declaration to your page:
xmlns:adduplex="using:AdDuplex.Universal.Controls.Win.XAML"

Add an AdControl to your page:
< adduplex:AdControl AdUnitId="xxxxxx" AppKey="xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" />

Then in Windows 8.1 Phone project:

Add a namespace declaration to your page:
xmlns:adduplex="using:AdDuplex.Universal.Controls.WinPhone.XAML"


Add an AdControl to your page:
< adduplex:AdControl AdUnitId="xxxxxx" AppKey="xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" />

Happy coding !


           

20 September 2015

How to fix JavaScript IntelliSense in Visual Studio

If you have situation, that after some update in Visual Studio (TypeScript, for example), when you edit a JavaScript file, IntelliSense not work, here is a fix procedure:

Make sure your computer has an internet connection, and
If the Tools for Universal Windows Apps Development are still installed:

Go to Programs and Features, select Visual Studio 2015, click Change.
In Visual Studio setup, click Modify.
Deselect the feature Tools for Universal Windows App Development.
Select Tools for Universal Windows App Development again, and click Update.

If you have already uninstalled the Tools for Universal Windows Apps Development:
Reinstall Tools for Universal Windows App Development.

Or, take the following steps to reinstall the JavaScript project system and language service:
Download the installer for your edition of Visual Studio, such as, vs_community.exe.
Open a command window, and run the following command:
vs_community.exe /modify /installselectableitems JavaScript_Hidden /passive

Change directories to C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE.
Run the following commands
devenv /updateconfiguration
devenv /clearcache

28 January 2015

Parse News RSS 2.0 image in C#

If you want to parse News RSS 2.0 image from link, for example > http://codecanyon.net/feeds/new-codecanyon-items.atom

The following code can be used to match all img src in the source text and to populate list with value of src attribute.

private static IEnumerable<string> GetImagesInHTMLString(string htmlString)
        {
            var images = new List<string>();
            const string pattern = Imgpattern;
            var rgx = new Regex(pattern, RegexOptions.IgnoreCase);
            MatchCollection matches = rgx.Matches(htmlString);

            for (int i = 0, l = matches.Count; i < l; i++)
            {
                if (matches[i].Value.Contains(".jpg") || matches[i].Value.Contains(".png"))
                {
                    var ms = Regex.Matches(matches[i].Value, Urlpattern);
                    if (ms.Count > 0)
                    {
                        if (!string.IsNullOrEmpty(ms[0].Value))
                            images.Add(ms[0].Value.Replace("\"", string.Empty));
                    }
                }
            }

            return images;
        }

Decompiled C# Library : AppStudio.Common.dll

Wonderfull Microsoft Windows AppStudio on adress http://appstudio.windows.com generate Universal Applications for Windows Phone and Windows Store in C# - online.

Downloaded generated source code use closed library AppStudio.Common.dll, which breaks further portability.

Fortunately, the only items being used from this library are the BindableBase, BindableSchemaBase, and IDataSource. 

So I recreated these files in the directly, removing the AppStudio.Common.dll reference entirely from both the  Windows projects.

Here’s the code for the BindableBase:

using System;
using System.Collectionus.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace SoftLabPro.Data
{ public abstract class BindableBase : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    protected BindableBase()
    {
    }
    public virtual void Initialize(IDictionary<string, string> parameters)
    {
    }
    protected void OnPropertyChanged(string propertyName = null)
    {
        PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
        if (propertyChanged != null)
        {
            try
            {
                propertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
            catch
            {
            }
        }
    }
    protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
    {
        if (object.Equals((T)storage, value))
        {
            return false;
        }
        storage = value;
        this.OnPropertyChanged(propertyName);
        return true;
    }
}
}

Here is BindableSchemaBase:

using System;
using System.Runtime.CompilerServices;
using System.Text;

namespace SoftLabPro.Data
{ public abstract class BindableSchemaBase : BindableBase
{
    public BindableSchemaBase()
    {
        this.Id = Guid.NewGuid().ToString();
    }
    public abstract string GetValue(string propertyName);
    public virtual string GetValues(params string[] propertyNames)
    {
        StringBuilder builder = new StringBuilder();
        foreach (string str in propertyNames)
        {
            builder.AppendLine((this.GetValue(str) ?? string.Empty).ToString());
        }
        return builder.ToString();
    }
    public abstract string DefaultContent { get; }
    public abstract string DefaultImageUrl { get; }
    public abstract string DefaultSummary { get; }
    public abstract string DefaultTitle { get; }
    public string Id { get; set; }
}
}


And finally IDataSource:

using System.Collections.Generic;

using System.Threading.Tasks;

namespace SoftLabPro.Data

{
    public interface IDataSource<T> where T : BindableSchemaBase

{
    Task<IEnumerable<T>> LoadData();
    Task<IEnumerable<T>> Refresh();
}

}

27 January 2015

Parse Google News RSS image in C#

If you want to parse Google News RSS image from link, for example > http://news.google.com/news?hl=us&q=android&output=rss

The following code can be used to match all img src in the source text and to populate list with value of src attribute.

private static IEnumerable<string> GetImagesInGoogleNewsString(string htmlString)
        {
            List<string> imgSrcs = new List<string>();
            //const string pattern = Imgpattern;
            //var rgx = new Regex(pattern, RegexOptions.IgnoreCase);
            var imgSrcMatches = System.Text.RegularExpressions.Regex.Matches(htmlString, string.Format(@"<\s*img\s*src\s*=\s*{0}\s*([^{0}]+)\s*{0}", "\""),
               RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | 
               RegexOptions.Multiline);

            foreach (Match match in imgSrcMatches)
                imgSrcs.Add("http:" + match.Groups[1].Value);

            return imgSrcs;
        }

07 September 2014

29 July 2014

How to disable Frame Rate Counter in Windows 8 Applications

To disable Frame Rate Counter in Windows 8 Applications there should enter next line in MainPage.xaml.cs on public MainPage() method :

public MainPage()
        {
            this.InitializeComponent();
            Application.Current.DebugSettings.EnableFrameRateCounter = false;
         }


23 July 2014

Windows Phone 8 and SQLite deploy to device error

On the Build tab, you’ll see Conditional compilation symbols under the General header, containing a default value of SILVERLIGHT;WINDOWS_PHONE on a Windows Phone app project. Change the value to SILVERLIGHT;WINDOWS_PHONE;USE_WP8_NATIVE_SQLITE and save the project file.

06 April 2014

Microsoft Visual Studio development versions and target platforms

It's a little bit confusing to choose which version of Visual Studio is for desired Windows Phone or Windows Store platform. So I create this table :

Platform
Development
MS Windows Phone 7
MS Visual Studio 2010 Express for Windows Phone

MS Visual Studio 2012 Express for Windows Phone
MS Windows Phone 8
MS Visual Studio 2012 Express for Windows Phone
MS Windows Phone 8.1
MS Visual Studio 2013 Express for Windows Update 2 RC
MS Windows 8 Store Application
MS Visual Studio 2012 Express for Windows
MS Windows 8.1 Store Application
MS Visual Studio 2013 Express for Windows Update 2 RC


05 November 2013

Getting 'System.IO.FileNotFoundException' in Windows Phone Project with Background Agent

If you start getting 'System.IO.FileNotFoundException' in Windows Phone Project with Background Agent, than you probably missed to add Reference in main project on background agent.

24 December 2011

C# Lesson 24 : Understanding Event-Driven Programming

Learn how events are utilized in the .NET Framework Class Library specific to WPF and ASP.NET Web Forms applications. In these examples, we see how C# is generated by the IDE to "wire up" a user action or application event to the code that handles that event.

WPF

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WPFEvents
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            MyButton.Click += MyButton_Click;
            MyButton.Click += MyButton_IClickedThis;
        }

        void MyButton_Click(object sender, RoutedEventArgs e)
        {
            //throw new NotImplementedException();
            MyLabel.Content = "Hello World!";
        }

        void MyButton_IClickedThis(object sender, RoutedEventArgs e)
        {
            //throw new NotImplementedException();
            MyLabel.Content = "Hello World again!";
        }

    }
}


ASP.NET

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ASPNETEvents
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MyButton.Click += MyButton_Click;
        }

        void MyButton_Click(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
            MyLabel.Text = "Hello world!";
        }

 
    }
}

Source : MS Virtual Academy

23 December 2011

C# Lesson 23 : Filtering and Managing Data Collections Using LINQ

In this lesson, we discuss how Structured Query Language provides a means of working with sets of data. Similarly, the LINQ syntax provides a simple way of working with groups of data in generic collections. We demonstrate projecting data onto existing types and new anonymous types.

Before

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UnderstandingLINQ
{
    class Program
    {
        static void Main(string[] args)
        {
            List<Car> myCars = new List<Car>() {
                new Car() { Make = "BMW", Model= "550i", Color=CarColor.Blue, StickerPrice=55000, Year=2009},
                new Car() { Make="Toyota", Model="4Runner", Color=CarColor.White, StickerPrice=35000, Year=2010},
                new Car() { Make="BMW", Model = "745li", Color=CarColor.Black, StickerPrice=75000, Year=2008},
                new Car() {Make="Ford", Model="Escape", Color=CarColor.White, StickerPrice=25000, Year=2008},
                new Car() {Make="BMW", Model="55i", Color=CarColor.Black, StickerPrice=57000, Year=2010}
            };

            foreach (var car in myCars)
                Console.WriteLine("{0} - {1} - {2}", car.Make, car.Model, car.Year);

            Console.ReadLine();
        }
    }

    class Car
    {
        public string Make { get; set; }
        public string Model { get; set; }
        public int Year { get; set; }
        public double StickerPrice { get; set; }
        public CarColor Color { get; set; }
    }

    enum CarColor
    {
        White,
        Black,
        Red,
        Blue,
        Yellow
    }

}


After

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UnderstandingLINQ
{
    class Program
    {
        static void Main(string[] args)
        {
            List<Car> myCars = new List<Car>() {
                new Car() { Make = "BMW", Model= "550i", Color=CarColor.Blue, StickerPrice=55000, Year=2009},
                new Car() { Make="Toyota", Model="4Runner", Color=CarColor.White, StickerPrice=35000, Year=2010},
                new Car() { Make="BMW", Model = "745li", Color=CarColor.Black, StickerPrice=75000, Year=2008},
                new Car() {Make="Ford", Model="Escape", Color=CarColor.White, StickerPrice=25000, Year=2008},
                new Car() {Make="BMW", Model="55i", Color=CarColor.Black, StickerPrice=57000, Year=2010}
            };

            /*
            var bmws = from car in myCars
                       where car.Make == "BMW"
                       && car.Year == 2010
                       select new { car.Make, car.Model, car.Year };
            */

            /*
            var orderedCars = from car in myCars
                              orderby car.Year descending
                              select car;
            */

            //var _bmws = myCars.Where(p => p.Year == 2010).Where(p => p.Make == "BMW");

            //var _orderedCars = myCars.OrderByDescending(p => p.Year);

            var sum = myCars.Sum(p => p.StickerPrice);

            /*
            foreach (var car in _orderedCars)
                Console.WriteLine("{0} - {1} - {2}", car.Make, car.Model, car.Year);
            */

            Console.WriteLine(sum);
            Console.ReadLine();
        }
    }

    class Car
    {
        public string Make { get; set; }
        public string Model { get; set; }
        public int Year { get; set; }
        public double StickerPrice { get; set; }
        public CarColor Color { get; set; }
    }

    enum CarColor
    {
        White,
        Black,
        Red,
        Blue,
        Yellow
    }

}
Source : MS Virtual Academy

22 December 2011

C# Lesson 22 : Working with Collections

Collections are a more powerful form of arrays. In this lesson, we demonstrate an "old style" collection (pointing out its limitations), along with several of the newer, strongly typed generic collections (List<T> and Dictionary<T1, T2>) utilizing the generics syntax.

Before

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WorkingWithCollections
{
    class Program
    {
        static void Main(string[] args)
        {
            Car car1 = new Car();
            car1.Make = "Oldsmobile";
            car1.Model = "Cutlas Supreme";

            Car car2 = new Car();
            car2.Make = "Geo";
            car2.Model = "Prism";

            Book b1 = new Book();
            b1.Author = "Robert Tabor";
            b1.Author = "Microsoft .NET XML Web Services";
            b1.ISBN = "0-000-00000-0";


            Console.ReadLine();
        }
    }

    class Car
    {
        public string Make { get; set; }
        public string Model { get; set; }
    }

    class Book
    {
        public string Title { get; set; }
        public string Author { get; set; }
        public string ISBN { get; set; }
    }

}


After

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WorkingWithCollections
{
    class Program
    {
        static void Main(string[] args)
        {
            /*
            Car car1 = new Car();
            car1.Make = "Oldsmobile";
            car1.Model = "Cutlas Supreme";

            Car car2 = new Car();
            car2.Make = "Geo";
            car2.Model = "Prism";

            Book b1 = new Book();
            b1.Author = "Robert Tabor";
            b1.Author = "Microsoft .NET XML Web Services";
            b1.ISBN = "0-000-00000-0";
             */

            // ArrayLists are dynamically sized, and support other
            // cool features like sorting, removing items, etc.
            /*
            System.Collections.ArrayList myArrayList = new System.Collections.ArrayList();
            myArrayList.Add(car1);
            myArrayList.Add(car2);
            myArrayList.Add(b1);
            myArrayList.Remove(b1);

            foreach (object o in myArrayList)
            {
                Console.WriteLine(((Car)o).Make);
            }
            */

            // Dictionaries allow you to save a key along with
            // the value, and also support cool features.
            // There are different dictionaries to choose from ...
            /*
            System.Collections.Specialized.ListDictionary myDictionary
                = new System.Collections.Specialized.ListDictionary();

            myDictionary.Add(car1.Make, car1);
            myDictionary.Add(car2.Make, car2);
            myDictionary.Add(b1.Author, b1);


            // Easy access to an element using its key
            Console.WriteLine(((Car)myDictionary["Geo"]).Model);

            // But since its not strongly typed, we can easily break it
            // by adding a different type to the dictionary ...
            // Obviously, I'm trying to retrieve a book here, and then get its ... model?
            Console.WriteLine(((Car)myDictionary["Robert Tabor"]).Model);
            */

            /*
            List<Car> myList = new List<Car>();

            myList.Add(car1);
            myList.Add(car2);
            //myList.Add(b1);

            foreach (Car car in myList)
            {
                // No casting!
                Console.WriteLine(car.Model);
            }
            */

            /*
            Dictionary<string, Car> myDictionary = new Dictionary<string, Car>();
            myDictionary.Add(car1.Make, car1);
            myDictionary.Add(car2.Make, car2);

            Console.WriteLine(myDictionary["Geo"].Model);
            */

            //string[] names = { "Bob", "Steve", "Brian", "Chuck" };


            Car car1 = new Car() { Make = "Oldsmobile", Model = "Cutlas Supreme" };
            Car car2 = new Car() { Make = "Geo", Model = "Prism" };
            Car car3 = new Car() { Make = "Nissan", Model = "Altima" };

            List<Car> myList = new List<Car>() {
                new Car { Make = "Oldsmobile", Model = "Cutlas Supreme"},
                new Car { Make = "Geo", Model="Prism"},
                new Car { Make = "Nissan", Model = "Altima"}
            };



            Console.ReadLine();
        }
    }

    class Car
    {
        public string Make { get; set; }
        public string Model { get; set; }
    }

    class Book
    {
        public string Title { get; set; }
        public string Author { get; set; }
        public string ISBN { get; set; }
    }

}
Source : MS Virtual Academy

21 December 2011

C# Lesson 21 : Gracefully Handling Exceptions

Exceptions occur when an application experiences some unexpected problem at run time. This lesson discusses how to use the try catch finally block to anticipate potential problems and to attempt to shield the end user from those problems as much as possible. We also explore best practices when checking for exceptions.

Before

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ReadTextFileWhile
{
    class Program
    {
        static void Main(string[] args)
        {
            StreamReader myReader = new StreamReader("Values.txt");
            string line = "";

            while (line != null)
            {
                line = myReader.ReadLine();
                if (line != null)
                    Console.WriteLine(line);
            }

            myReader.Close();
            Console.ReadLine();

        }
    }
}


After

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ReadTextFileWhile
{
    class Program
    {
        static void Main(string[] args)
        {

            try
            {

                StreamReader myReader = new StreamReader("Values.txt");
                string line = "";

                while (line != null)
                {
                    line = myReader.ReadLine();
                    if (line != null)
                        Console.WriteLine(line);
                }

                myReader.Close();

            }
            catch (DirectoryNotFoundException e)
            {
                Console.WriteLine("Couldn't fine the file.  Are you sure the DIRECTORY exists?");
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine("Couldn't find the file.  Are you sure you're looking for the correct file?");
            }
            catch (Exception e)
            {
                Console.WriteLine("Something didn't quite work correctly: {0}", e.Message);
            }
            finally
            {
                // Perform any cleanup to roll back the data or close connections
                // to files, database, network, etc.
            }

            Console.ReadLine();

        }
    }
}

Source : MS Virtual Academy

20 December 2011

C# Lesson 20 : Enumerations and the switch Decision Statement

Here, we demonstrate the use of Enumerations because, in the .NET Framework Class Library, properties can often be set only to a predetermined subset of possible values. To illustrate this point, we create our own custom enumeration and then utilize it in a simple application that demonstrates a third Decision statement, the switch.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UsingSwitch
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Type in a super hero's name to see his nickname:");
            string userValue = Console.ReadLine();

            switch(userValue.ToUpper())
            {
                case "BATMAN":
                    Console.WriteLine("Caped Crusader");
                    break;
                case "SUPERMAN":
                    Console.WriteLine("Man of Steel");
                    break;
                case "GREENLANTERN":
                    Console.WriteLine("Emerald Knight");
                    break;
                default:
                    Console.WriteLine("Does not compute");
                    break;
            }


            Console.ReadLine();

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UnderstandingEnumerations
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.DarkRed;
            //Console.WriteLine("Hello world!");

            Console.WriteLine("Type in a superhero's name to see his nickname: ");
            string userValue = Console.ReadLine();

            SuperHero myValue;

            if (Enum.TryParse<SuperHero>(userValue, true, out myValue))
            {
                switch (myValue)
                {
                    case SuperHero.Batman:
                        Console.WriteLine("Caped crusader");
                        break;
                    case SuperHero.Superman:
                        Console.WriteLine("Man of Steel");
                        break;
                    case SuperHero.GreenLantern:
                        Console.WriteLine("Emerald Knight");
                        break;
                    default:
                        break;
                }
            }
            else
            {
                Console.WriteLine("Does not compute");
            }

            Console.ReadLine();
        }
    }

    enum SuperHero
    {
        Batman,
        Superman,
        GreenLantern
    }

}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ComplexIfStatement
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Pick a number between 1 and 100:");
            string userValue = Console.ReadLine();

            int compareValue = int.Parse(userValue);

            if ((compareValue < 1) || (compareValue > 100))
                Console.WriteLine("The number you chose was out of bounds.");
            else if ((compareValue == 42) || (compareValue > 90))
                Console.WriteLine("You found one of the special numbers!");
            else
                Console.WriteLine("You didn't find one of the special numbers");

            Console.ReadLine();

        }
    }
}

19 December 2011

C# Lesson 19 : Understanding Scope and Utilizing Accessibility Modifiers

Explore the scope of variables within code blocks and how accessibility modifiers, such as Public, Private, and Protected, are used by the .NET Framework Class Library to expose or hide implementation of their given services to consumers of that given class. This is sometimes referred to as "encapsulation."

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UnderstandingScope
{
    class Program
    {
       // private static string k = "";

        static void Main(string[] args)
        {
            /*
            string j = "";

            for (int i = 0; i < 10; i++)
            {
                j = i.ToString();
                k = i.ToString();
                Console.WriteLine(i);

                if (i == 9)
                {
                    string l = i.ToString();
                }
                //Console.WriteLine("l: " + l);
            }
            //Console.WriteLine(i);

            Console.WriteLine("Outsite of the for: " + j);
            //Console.WriteLine("k: " + k);
            helperMethod();
             */


            Car car = new Car();

            car.DoSomething();


            Console.ReadLine();
        }

        /*
        static void helperMethod()
        {
            Console.WriteLine("k from the helperMethod: " + k);
        }
         */

    }

    class Car
    {
        public void DoSomething()
        {
            Console.WriteLine(helperMethod());
        }

        private string helperMethod()
        {
            return "Hello world!";
        }

    }

}
Source : MS Virtual Academy

18 December 2011

C# Lesson 18 : Understanding Namespaces and Adding References to Assemblies

In this lesson, we explain how Namespaces allow us to disambiguate classes that may share the same name. And we explain how the .NET Framework Class Library is so large that including all its classes in every application you write is a waste of system resources. Certain project templates include references to the typical assemblies required by a given type of application, and we demonstrate this by referencing a custom assembly of Bob's own design.

using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tabor;

namespace NamespacesAndReferencingAssemblies
{
    class Program
    {
        static void Main(string[] args)
        {
            //System.IO.StreamReader myStreamReader = new System.IO.StreamReader();

            //StreamReader myStreamReader = new StreamReader();


            Bob bob = new Bob();

            string html = bob.Lookup("http://www.learnvisualstudio.net");

            Console.WriteLine(html);
            Console.ReadLine();


        }
    }
}
Source : MS Virtual Academy

17 December 2011

C# Lesson 17 : Working with Classes and Inheritances in the .NET Framework Class Library

This lesson continues to teach concepts about classes (specifically, in this case, inheritance) by showing you how to utilize inheritance in your own custom classes. Learn about overriding virtual functionality, abstract base classes, and sealed classes. 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UnderstandingInheritance
{
    class Program
    {
        static void Main(string[] args)
        {
            Car myCar = new Car();
            myCar.Make = "BMW";
            myCar.Model = "745li";
            myCar.Color = "Black";
            myCar.Year = 2005;
            //myCar.TowingCapacity = 1200;

            printVehicleDetails(myCar);


            Truck myTruck = new Truck();

            myTruck.Make = "Ford";
            myTruck.Model = "F950";
            myTruck.Year = 2006;
            myTruck.Color = "Black";
            myTruck.TowingCapacity = 1200;
            printVehicleDetails(myTruck);

            Console.ReadLine();
        }

        private static void printVehicleDetails(Vehicle vehicle)
        {
            Console.WriteLine("Here are the vehcile's details: {0}",
                vehicle.FormatMe());
        }

    }

    abstract class Vehicle
    {
        public string Make { get; set; }
        public string Model { get; set; }
        public int Year { get; set; }
        public string Color { get; set; }

        public abstract string FormatMe();
    }

    class Car : Vehicle
    {
        public override string FormatMe()
        {
            return String.Format("{0} - {1} - {2} - {3}",
                this.Make,
                this.Model,
                this.Color,
                this.Year);
        }
    }

    sealed class Truck : Vehicle
    {
        public int TowingCapacity { get; set; }

        public override string FormatMe()
        {
            return String.Format("{0} - {1} - {2} Towing units",
                this.Make,
                this.Model,
                this.TowingCapacity);
        }

    }

    /*
    class Semi : Truck
    {

    }
    */

}
Source : MS Virtual Academy