 
  
   
  
  RowDefinitionCollection rd = MainGrid.RowDefinitions;
ColumnDefinitionCollection cd = MainGrid.ColumnDefinitions;
for (int i = 0; i < 3; i++)
{
    rd.Add(new RowDefinition());
    for (int j = 0; j < 12; j++)
    {
      cd.Add(new ColumnDefinition());
      Button b = new Button();
      b.Name = "Button"+i;
      MainGrid.Children.Add(b);
      Grid.SetColumn(b, j);
      Grid.SetRow(b, i);
    } 
} 
  
   
  
  SetCurrentValue(BrushClass.BrushProperty, 5);
<Window x:Class="WpfApplication3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication3"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Image Name="image" HorizontalAlignment="Left" Height="282" Margin="18,18,0,0" VerticalAlignment="Top" Width="394" Source="{Binding MySource}"/>
        <Button Name="button" Content="Button" HorizontalAlignment="Left" Margin="432,18,0,0" VerticalAlignment="Top" Width="75" Click="button_Click"/>
    </Grid>
</Window>using Microsoft.Win32;
using System;
using System.ComponentModel;
using System.Windows;
namespace WpfApplication3
{
    public partial class MainWindow : Window
    {
        public MyClass Class;
        public MainWindow()
        {
            InitializeComponent();
            Class = new MyClass();
            image.DataContext = Class;
        }
        private void button_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog myDialog = new OpenFileDialog();
            if (myDialog.ShowDialog().Value)
                Class.MySource = myDialog.FileName;
        }
    }
    public class MyClass : INotifyPropertyChanged
    {
        private String mySource;
        public String MySource
        {
            get
            {
                return mySource;
            }
            set
            {
                mySource = value;
                OnPropertyChanged("MySource");
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
} 
  
  ComboBoxItem lbi = ((sender as ComboBox).SelectedItem as ComboBoxItem);lbi может находиться null, если ничего не выбрано, т.к. as возвращает null, если преобразование не удалось.Content у null. Об этом компилятор и сообщает.null перед использованием lbi       
  
  то делать дальше?
1. перечитать книгу
2. Прочитать новую
3. Начать ещё одну
bool checkPalindrome(string inputString)
        {
            if (string.IsNullOrWhiteSpace(inputString))
            {
                return false;
            }
            else
            {
                char[] arr = inputString.ToCharArray();
                Array.Reverse(arr); 
                if (inputString == new string(arr))
                {
                    return true;
                }
                else
                {
                    return false;
                } 
            } 
        }var h = checkPalindrome("aaaabcaaaa");str.ToCharArray(1, inputString.Length);static bool checkPalindrome(string inputString)
        {
            bool flag = true;
            string str = inputString;
            char[] array = str.ToCharArray(0, inputString.Length);
            if (string.IsNullOrWhiteSpace(inputString))
            {
                return false;
            }
            else
            {
                for (int i = 0; i < array.Length; i++)
                {
                    while (array[i] == array[i + 1])
                    {
                        if (array[i] == array[-i]) //aaaabcaaaa
                        { 
                            return true;
                        }
                        else
                        { 
                            return false;
                        }
                    }
                }
                return flag;
            }
        } 
  
  Ведь c# - это компилируемый язык а не интерпретируемый, а значит код не читается строчка за строчкой а строится синтаксическое дерево. И поэтому мне интересно не все ли равно где объявлять пространства имен?